2、redis常用命令详解
2.1、redis编译安装命令查看
[root@mysqldb1 redis-3.0.5]#cd /usr/local/bin
[root@mysqldb1 bin]# ll | grep redis
-rwxr-xr-x. 1 root root 4587299 Nov 2 01:26 redis-benchmark
-rwxr-xr-x. 1 root root 22177 Nov 2 01:26 redis-check-aof
-rwxr-xr-x. 1 root root 45387 Nov 2 01:26 redis-check-dump
-rwxr-xr-x. 1 root root 4691450 Nov 2 01:26 redis-cli
lrwxrwxrwx. 1 root root 12 Nov 2 01:26 redis-sentinel -> redis-server
-rwxr-xr-x. 1 root root 6464789 Nov 2 01:26 redis-server
2.2、redis-benchmark是Redis性能测试工具,测试Redis在你的系统及你的配置下的读写性能,redis的基准信息和性能检测。
redis-benchmark参数:
[root@mysqldb1 ~]# redis-benchmark --help
Usage: redis-benchmark [-h <host>] [-p <port>] [-c <clients>] [-n <requests]> [-k <boolean>]
-h <hostname> Server hostname (default 127.0.0.1)
设置检测主机IP地址,默认为127.0.0.1
-p <port> Server port (default 6379)
设置检测主机的端口号,默认为6379
-s <socket> Server socket (overrides host and port)
<socket> 服务器套接字(压到主机和端口)
-a <password> Password for Redis Auth
-c <clients> Number of parallel connections (default 50)
客户端并发连接数
-n <requests> Total number of requests (default 100000)
客户端总共发出的请求数
-d <size> Data size of SET/GET value in bytes (default 2)
测试使用的数据集的大小/字节的值(默认2字节)
-dbnum <db> SELECT the specified db number (default 0)
-k <boolean> 1=keep alive 0=reconnect (default 1)
1:表示保持连接(默认值)0:重新连接
-r <keyspacelen> Use random keys for SET/GET/INCR, random values for SADD
Using this option the benchmark will expand the string __rand_int__
inside an argument with a 12 digits number in the specified range
from 0 to keyspacelen-1. The substitution changes every time a command
is executed. Default tests use this to hit random keys in the
specified range.
SET/GET/INCR方法使用随机数插入数值,如果设置为100则插入值为rand:000000000000 - rand:000000000099
-P <numreq> Pipeline <numreq> requests. Default 1 (no pipeline).
默认为1(无管道),当网络延迟过长时,使用管道方式通信(请求和响应打包发送接收)
-q Quiet. Just show query/sec values
简约信息模式,只显示查询和秒值等基本信息。
--csv Output in CSV format
以CSV格式输出信息
-l Loop. Run the tests forever
无线循环插入测试数据,ctrl+c停止
-t <tests> Only run the comma separated list of tests. The test
names are the same as the ones produced as output.
只运行<tests>测试逗号分隔的列表命令,如:-t ping,set,get
-I Idle mode. Just open N idle connections and wait.
空闲模式。立即打开50个空闲连接和等待。
Examples:
Run the benchmark with the default configuration against 127.0.0.1:6379:
$ redis-benchmark
Use 20 parallel clients, for a total of 100k requests, against 192.168.1.1:
$ redis-benchmark -h 192.168.1.1 -p 6379 -n 100000 -c 20
Fill 127.0.0.1:6379 with about 1 million keys only using the SET test:
$ redis-benchmark -t set -n 1000000 -r 100000000
Benchmark 127.0.0.1:6379 for a few commands producing CSV output:
$ redis-benchmark -t ping,set,get -n 100000 --csv
Benchmark a specific command line:
$ redis-benchmark -r 10000 -n 10000 eval 'return redis.call("ping")' 0
Fill a list with 10000 random elements:
$ redis-benchmark -r 10000 -n 10000 lpush mylist __rand_int__
On user specified command lines __rand_int__ is replaced with a random integer
with a range of values selected by the -r option.
2.3、redis-cli 的使用说明
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 root@mysqldb1 ~]# redis-cli --help
redis-cli 3.0.5
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).
-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 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.
2.4、redis-check-aof
更新日志检查 ,加--fix参数为修复log文件
redis-check-aof appendonly.aof
2.5、 redis-check-dump
检查本地数据库文件
redis-check-dump dump.rdb