Some interesting and useful features of redis-cli
[root@tadu_redis_115 scripts]# /usr/local/redis24/bin/redis-cli -h
redis-cli 2.4.15
Usage: redis-cli [OPTIONS] [cmd [arg [arg ...]]]
-h <hostname> Server hostname (default: 127.0.0.1)
-p <port> Server port (default: 6379)
-s <socket> Server socket (overrides hostname and port)
-a <password> Password to use when connecting to the server
-r <repeat> Execute specified command N times
-i <interval> When -r is used, waits <interval> seconds per command.
It is possible to specify sub-second times like -i 0.1.
-n <db> Database number
-x Read last argument from STDIN
-d <delimiter> Multi-bulk delimiter in for raw formatting (default: \n)
--raw Use raw formatting for replies (default when STDOUT is not a tty)
--latency Enter a special mode continuously sampling latency.
--slave Simulate a slave showing commands received from the master.
--pipe Transfer raw Redis protocol from stdin to server.
--bigkeys Sample Redis keys looking for big keys.
--help Output this help and exit
--version Output version and exit
Examples:
cat /etc/passwd | redis-cli -x set mypasswd
redis-cli get mypasswd
redis-cli -r 100 lpush mylist x
redis-cli -r 100 -i 1 info | grep used_memory_human:
When no command is given, redis-cli starts in interactive mode.
Type "help" in interactive mode for information on available commands.
http://www.tuicool.com/articles/Yvqm2ev
The two most commonly used parameters of redis-cli are the -h, -p, -a options, which assign the host and port of the redis-server to specify the connection.
Through redis-cli –help, redis-cli also provides many other parameters and functions.The -xx option reads the last argument from standard input (stdin). For example to read input from a pipe:
echo -en "chen.qun" | redis-cli -x set name
-r -i
The -r option repeats a command the specified number of times.
-i Sets the interval for command execution.
For example, to view the commands (qps) executed by redis per second
redis-cli -r 100 -i 1 info stats | grep instantaneous_ops_per_sec
-c enables redis cluster mode, which is used when connecting to redis cluster nodes.
–rdb Get the rdb file of the specified redis instance and save it locally.
redis-cli -h 192.168.44.16 -p 6379 --rdb 6379.rdb
--slave simulates commands that slave receives from master. The commands received on the slave are all update operations, which record the update behavior of data.
–scan and –pattern are used to scan the key in redis with the scan command. The –pattern option specifies the pattern of the scanned key. Compared with the keys pattern mode, it will not block redis for a long time and cause the command requests of other clients to be blocked all the time.
redis-cli --scan --pattern 'chenqun_*'
–pipe
This is a very useful parameter. Send the original redis protocl format data to the server for execution.
For example, the data in the following form (the linux server needs to be converted into a dos file with unix2dos).
The default newline under linux is \n, the newline character of windows system is \r\n, and redis uses \r\n.
echo -en '*3\r\n$3\r\nSET\r\n$3\r\nkey\r\n$5\r\nvalue\r\n' | redis-cli --pipe
Reference: http://redis.io/topics/mass-insert
--bigkeys Sampling keys in redis looking for larger keys. The scan method is used, so don't worry about blocking redis for a long time and unable to process other requests. The results of the execution can be used to analyze the memory usage status of redis and the average size of each type of key.
redis -cli --bigkeys
--eval executes the specified lua script.
redis-cli --eval myscript.lua key1 key2 , arg1 arg2 arg3
=
=
=
1
1
1
1