Redis Shell

redis-cli

相关选项的作用持续补充中…

[root@localhost redis]# ./redis-cli --help
redis-cli 4.0.6

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.
  -u <uri>           Server URI.
  -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).
  -c                 Enable cluster mode (follow -ASK and -MOVED redirections).
  --raw              Use raw formatting for replies (default when STDOUT is
                     not a tty).
  --no-raw           Force formatted output even when STDOUT is not a tty.
  --csv              Output in CSV format.
  --stat             Print rolling stats about server: mem, clients, ...
  --latency          Enter a special mode continuously sampling latency.
                     If you use this mode in an interactive session it runs
                     forever displaying real-time stats. Otherwise if --raw or
                     --csv is specified, or if you redirect the output to a non
                     TTY, it samples the latency for 1 second (you can use
                     -i to change the interval), then produces a single output
                     and exits.
  --latency-history  Like --latency but tracking latency changes over time.
                     Default time interval is 15 sec. Change it using -i.
  --latency-dist     Shows latency as a spectrum, requires xterm 256 colors.
                     Default time interval is 1 sec. Change it using -i.
  --lru-test <keys>  Simulate a cache workload with an 80-20 distribution.
  --slave            Simulate a slave showing commands received from the master.
  --rdb <filename>   Transfer an RDB dump from remote server to local file.
  --pipe             Transfer raw Redis protocol from stdin to server.
  --pipe-timeout <n> In --pipe mode, abort with error if after sending all data.
                     no reply is received within <n> seconds.
                     Default timeout: 30. Use 0 to wait forever.
  --bigkeys          Sample Redis keys looking for big keys.
  --hotkeys          Sample Redis keys looking for hot keys.
                     only works when maxmemory-policy is *lfu.
  --scan             List all keys using the SCAN command.
  --pattern <pat>    Useful with --scan to specify a SCAN pattern.
  --intrinsic-latency <sec> Run a test to measure intrinsic system latency.
                     The test will run for the specified amount of seconds.
  --eval <file>      Send an EVAL command using the Lua script at <file>.
  --ldb              Used with --eval enable the Redis Lua debugger.
  --ldb-sync-mode    Like --ldb but uses the synchronous Lua debugger, in
                     this mode the server is blocked and script changes are
                     are not rolled back from the server memory.
  --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:
  redis-cli --eval myscript.lua key1 key2 , arg1 arg2 arg3
  redis-cli --scan --pattern '*:12345*'

  (Note: when using --eval the comma separates KEYS[] from ARGV[] items)

When no command is given, redis-cli starts in interactive mode.
Type "help" in interactive mode for information on available commands
and settings.

-h -p -a常用命令,直接忽略了

参数描述
-r Execute specified command N times.(执行指定的命令N次。)
-r When -r is used, waits seconds per command.It is possible to specify sub-second times like -i 0.1.(当使用-r时,每个命令等待<interval>秒。可以指定次秒时间,如-i 0.1。)
-xRead last argument from STDIN.(读标准输入中的最后一个参数)
-aredis.conf中存在requirepass ${passwd}配置
–pipeTransfer raw Redis protocol from stdin to server.(将原始Redis协议从标准输入传输到服务器。)这个命令很重要,将关系型的数据批量导入redisy要使用到这个命令
#执行ping命令3次
./redis-cli -h 192.168.42.111 -r 3 ping
PONG
PONG
PONG
#每隔2秒执行一次ping命令,一共执行3次
 ./redis-cli -h 192.168.42.111 -r 3 -i 2 ping
PONG
PONG
PONG
#每隔10ms执行一次ping命令,一共执行3次
 ./redis-cli -h 192.168.42.111 -r 3 -i 0.01 ping
PONG
PONG
PONG
#没有使用-r选项,没有报错的,当PONG输出后2s才退出
./redis-cli -h 192.168.42.111 -i 2 ping
PONG
#set hello world
echo "world" | ./redis-cli -h 192.168.42.111 -x set hello
OK
#get hello 
 ./redis-cli -h 192.168.42.111 get hello                   
"world\n"
#strlen hello  --6
 ./redis-cli -h 192.168.42.111 strlen hello         
(integer) 6
#注意点
#1.echo需要加上-e选项(启用反斜杠转义的解释)
echo -e '*3\r\n$3\r\nset\r\n$5\r\nhello\r\n$5\r\nworld\r\n*2\r\n$4\r\nincr\r\n$5\r\ncount\r' | ./redis-cli -h 192.168.42.111 --pipe
All data transferred. Waiting for the last reply...
Last reply received from server.
errors: 0, replies: 2
#不加-e选项的错误
echo  '*3\r\n$3\r\nset\r\n$5\r\nhello\r\n$5\r\nworld\r\n*2\r\n$4\r\nincr\r\n$5\r\ncount\r' | ./redis-cli -h 192.168.42.111 --pipe
All data transferred. Waiting for the last reply...
ERR Protocol error: invalid multibulk length
No replies for 30 seconds: exiting.
errors: 2, replies: 1
#2.注意echo命令最后的\r\n只能是\r,不然就会报下面的错
echo -e '*3\r\n$3\r\nset\r\n$5\r\nhello\r\n$5\r\nworld\r\n*2\r\n$4\r\nincr\r\n$5\r\ncount\r\n' | ./redis-cli -h 192.168.42.111 --pipe
All data transferred. Waiting for the last reply...
ERR unknown command '2'
ERR unknown command '$4'
ERR wrong number of arguments for 'echo' command
ERR unknown command '$20'
ERR unknown command '洞芽延q鶨拔O汾霔C'
#可以加上 -n选项来规避在echo命令在最后加上\n的问题
echo -e -n '*3\r\n$3\r\nset\r\n$5\r\nhello\r\n$5\r\nworld\r\n*2\r\n$4\r\nincr\r\n$5\r\ncount\r\n' | ./redis-cli -h 192.168.42.111 --pipe
./redis-cli -h 192.168.42.111 --pipe
All data transferred. Waiting for the last reply...
Last reply received from server.
errors: 0, replies: 2
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值