Overview of redis-cli and redis-benchmark
Obtaining redis-cli and redis-benchmark
Create an ECS and install the Redis server matching the OS. The following examples use Ubuntu and CentOS.
You can compile and install Redis, or use yum and apt to install the Redis server. When the Redis server is installed, redis-benchmark is also installed.
- Ubuntu
sudo apt update sudo apt install redis-server
- CentOS
sudo yum install epel-release sudo yum update sudo yum -y install redis
You can also download the installation package, decompress it, and then compile it. The following uses redis-6.0.9 as an example:
- Download the redis-6.0.9 client.
- Decompress the client installation package.
- Go to the src directory of redis-6.0.9.
cd redis-6.0.9/src
- Compile the source code.
After the compilation is complete, the tool is stored in the src directory of redis-x.x.x.
Common redis-cli Options
- -h <hostname>: host name of the server, which can be an IP address or a domain name.
- -p <port>: port of the server. The default port is 6379.
- -a <password>: password for connecting to the server. This parameter is not required for password-free instances.
- -r <repeat>: number of times that a command is run.
- -n <db>: DB number. The default value is 0.
- -c: cluster mode (with -ASK and -MOVED redirections).
- --latency: a loop where latency is measured continuously.
- --scan: scans the key space without blocking the Redis server. (By contrast, scanning using KEYS * blocks Redis server).
- --eval <file>: sends the EVAL command using a Lua script.
- -x: reads the last parameter in stdin.
- --bigscan: scans big keys in the data set.
- --raw: forces raw data output from the hexadecimal format, such as \xe4\xb8.
For more information about redis-cli, visit https://redis.io/docs/manual/cli/.
Examples of Common redis-cli Commands
- Connect to an instance:
- Connect to a specified DB:
- Connect to a Redis Cluster instance:
- Test the latency (by sending the ping command):
./redis-cli -h {IP} -p 6379 --latency
- Scan for keys that match the specified pattern:
Common Options in redis-benchmark (redis-6.0.9)
- -h <hostname>: host name of the server, which can be an IP address or a domain name.
- -p <port>: port of the server. The default port is 6379.
- -a <password>: password for connecting to the server. This parameter is not required for password-free instances.
- -c <clients>: number of concurrent connections. The default value is 50.
- -n <requests>: total number of requests. The default value is 100000.
- -d <size>: data size of the SET/GET value, in bytes. The default value is 2.
- --dbnum <db >: database number. The default value is 0.
- --threads <num>: multi-thread mode, which is supported only by redis-benchmark compiled in Redis 6.0. In pressure tests, the multi-thread mode outperforms the single-thread mode.
- --cluster: cluster mode (required only by Redis Cluster).
- -k <boolean>: 1=keep alive; 0=reconnect. The default value is 1, indicating that both pconnect and connect can be tested.
- -r <keyspacelen>: uses random keys for SET, GET, and INCR, and random values for SADD. keyspacelen indicates the number of keys to be added.
- -e: displays server errors to stdout.
- -q: displays only the number of queries per second.
- -l: runs tests in loops.
- -t <tests>: tests specified commands.
- -I: idle mode. Open N idle connections and wait.
- -P <numreq>: concurrent pipeline requests. The default value is 1.
For more information about redis-benchmark, visit https://redis.io/docs/reference/optimization/benchmarks/.
Examples of Common redis-benchmark Commands
- Test single-node, master/standby, read/write splitting, and Proxy Cluster instances:
./redis-benchmark -h {IP address or domain name} -p 6379 -a {pwd}--threads {num} -n { nreqs } -r { randomkeys } -c {clients} -d {datasize} -t {command}
- Test Redis Cluster instances:
./redis-benchmark -h {IP address or domain name} -p 6379 -a {pwd}--threads {num} -n { nreqs } -r { randomkeys } -c {clients} -d {datasize} --cluster -t {command}
- Test connect:
./redis-benchmark -h {IP address or domain name} -p 6379 -a {pwd}--threads {num} -n { nreqs } -r { randomkeys } -c {clients} -d {datasize} -k 0 -t {command}
- Test idle connections:
./redis-benchmark -h {IP address or domain name} -p 6379 -a {pwd} -c {clients} -I
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.