redis shell

redis-cli

  • redis-cli -r (repeat)表示命令执行多次,
wusong@ubuntu:~$ redis-cli -r 3 ping
PONG
PONG
PONG
  • -i (interval)表示每隔几秒执行一次命令,-i和-r选项必须一起使用,-i 的单位是秒,不支持毫秒,可以使用小数表示毫秒,-i0.001表示10毫秒。
wusong@ubuntu:~$ redis-cli -r 5 -i 1 ping
PONG
PONG
PONG
PONG
PONG
  • -x 选项代表从标准输入读取数据作为redis-cli的最后一个参数,
wusong@ubuntu:~$ echo "world" | redis-cli -x set hello
OK
wusong@ubuntu:~$ redis-cli get hello
"world\n"
wusong@ubuntu:~$ 
  • -c (cluster) 选项是连接Redis Cluster节点时需要使用的。
  • -a (auth)有了这个选项就不需要手动输入auth命令。
  • –slave 把当前客户端模拟成当前redis节点的从节点。
wusong@ubuntu:~$ redis-cli  --slave // 开启一个客户端
SYNC with master, discarding 555 bytes of bulk transfer...
SYNC done. Logging commands from master.
wusong@ubuntu:~$ redis-cli set name ziyan // 另外一个客户端做更新操作
OK
wusong@ubuntu:~$ redis-cli set age 26
OK
wusong@ubuntu:~$ 
wusong@ubuntu:~$ redis-cli  --slave  // 第一个客户端会收到更新操作
SYNC with master, discarding 555 bytes of bulk transfer...
SYNC done. Logging commands from master.
"PING"
"PING"
"PING"
"PING"
"PING"
"SELECT","0"
"set","name","ziyan"
"PING"
"set","age","26"
  • –rdb 选项会请求redis实例生成并发送rdb持久化文件,保存在本地。

  • –pipe 选用用于将命令封装成Redis通信协议定义的数据格式,批量发送给redis。

  • –stat 选项可以实时获取Redis的重要统计信息

 redis-cli --stat
------- data ------ --------------------- load -------------------- - child -
keys       mem      clients blocked requests            connections          
15         798.28K  1       0       67 (+0)             15          
15         798.28K  1       0       68 (+1)             15          
15         798.28K  1       0       69 (+1)             15          
15         798.28K  1       0       70 (+1)             15          
15         798.28K  1       0       71 (+1)             15  

redis-server

      redis-server 除了启动redis之外,–test-memory : 用来检测当前操作系统能否稳定地分配指定容量的内存给redis,整个内存检测的时间比较长,当输出passed this test说明内存检测完毕。

redis-server --test-memory 1024

redis-benchmark

  • -c (client)选项代表客户端的并发数量(默认50)。
  • -n (num) 选项代表客户端请求总量。(默认100000)
redis-benchmark -c 100 -n200000 // 代表100个客户端同时请求redis,一共执行200000次。

      redis-benchmark会对各类数据结构的命令进行测试,并给出性能指标。如下所示,一共执行了2000次lpush操作,在0.06s完成,每个数据的请求量是3个字节,99.7%的命令执行时间小于1毫秒,Redis每秒可以处理30769.23次lpush请求。

 redis-benchmark -c 10 -n 2000

====== LPUSH ======
  2000 requests completed in 0.06 seconds
  10 parallel clients
  3 bytes payload
  keep alive: 1

97.70% <= 1 milliseconds
99.70% <= 2 milliseconds
100.00% <= 2 milliseconds
30769.23 requests per second

====== LRANGE_600 (first 600 elements) ======
  2000 requests completed in 0.25 seconds
  10 parallel clients
  3 bytes payload
  keep alive: 1

91.20% <= 1 milliseconds
100.00% <= 1 milliseconds
7968.13 requests per second
  • -q 选项仅仅显示redis-benchmark的request per second信息。

wusong@ubuntu:~$ redis-benchmark -c 50 -n 20000 -q
PING_INLINE: 56497.18 requests per second
PING_BULK: 56338.03 requests per second
SET: 49627.79 requests per second
GET: 52910.05 requests per second
INCR: 56179.77 requests per second
LPUSH: 56179.77 requests per second
LPOP: 40733.20 requests per second
SADD: 51679.59 requests per second
SPOP: 50505.05 requests per second
LPUSH (needed to benchmark LRANGE): 37735.85 requests per second
LRANGE_100 (first 100 elements): 19607.84 requests per second
LRANGE_300 (first 300 elements): 9896.09 requests per second
LRANGE_500 (first 450 elements): 8285.00 requests per second
LRANGE_600 (first 600 elements): 6191.95 requests per second
MSET (10 keys): 31446.54 requests per second
  • -r (random) 在一个空的redis上执行了redis-bench mark会发现只有3个键,如果想向redis插入更多的键,使用-r选项,-r1000代表只对后四位做随机处理。
127.0.0.1:6379> dbsize
(integer) 3
127.0.0.1:6379> keys *
1) "counter:__rand_int__"
2) "mylist"
3) "key:__rand_int__"
127.0.0.1:6379> 
 redis-benchmark -c 50 -n 20000 -q -r 1000

127.0.0.1:6379> dbsize
(integer) 2001
127.0.0.1:6379> scan 0
1) "1792"
2)  1) "counter:000000000431"
    2) "key:000000000766"
    3) "key:000000000644"
    4) "key:000000000257"
    5) "key:000000000174"
    6) "key:000000000497"
    7) "counter:000000000861"
    8) "counter:000000000443"
    9) "counter:000000000827"
   10) "counter:000000000285"
  • -t 选项可以对指定命令进行基准测试
 redis-benchmark -t get,set -q  
SET: 57372.34 requests per second
GET: 51203.28 requests per second
    原文作者:tracy_666
    原文地址: https://www.jianshu.com/p/ca1931ab1a8d
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞