Redis 命令
Redis 命令Redis 命令用于在 redis 服务上执行操作。要在 redis 服务上执行命令需要一个 redis 客户端。Redis 客户端在我们之前下载的的 redis 的安装包中。语法Redis 客户端的基本语法为:$ redis-cli实例以下实例讲解了如何启动 redis 客户端:启动 redis 客户端,打开终端并输入命令 redis-cli。该命令会连接本地的 redis 服务。$redis-cliredis 127.0.0.1:6379>
redis 127.0.0.1:6379> PING
PONG在以上实例中我们连接到本地的 redis 服务并执行 PING 命令,该命令用于检测 redis 服务是否启动。在远程服务上执行命令如果需要在远程 redis 服务上执行命令,同样我们使用的也是 redis-cli 命令。语法
$ redis-cli -h host -p port -a password
实例以下实例演示了如何连接到主机为 127.0.0.1,端口为 6379 ,密码为 mypass 的 redis 服务上。$redis-cli -h 127.0.0.1 -p 6379 -a "mypass"
redis 127.0.0.1:6379> PING
PONG
显示帮助
$redis-cli--help
>redis-cli --helpredis-cli 3.0.501
Usage: redis-cli ]]-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).-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.--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.--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>.--help Output this help and exit.--version Output version and exit.
Examples:cat /etc/passwd | redis-cli -x set mypasswdredis-cli get mypasswdredis-cli -r 100 lpush mylist xredis-cli -r 100 -i 1 info | grep used_memory_human:redis-cli --eval myscript.lua key1 key2 , arg1 arg2 arg3redis-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.
页:
[1]