Redis笔记(三)之Shell

redis版本

  1. redis版本:3.2.11

Redis Shell

  1. Redis提供了redis-cliredis-serverredis-benchmark等shell工具。

Redis-cli

  1. 帮助命令

        # redis-cli --help
        redis-cli 3.2.11
        ...省略输出...    
    
  2. -r(repeat):将命令执行多次

        执行3次ping
        # redis-cli -r 3 ping
        PONG
        PONG
        PONG
    
  3. -i(interval):每隔几秒执行一次命令

        每隔1秒执行一次,总共执行2次
        # redis-cli -r 2 -i 1 ping
        PONG
        PONG
        每隔10毫秒执行一次,总共执行2次
        # redis-cli -r 2 -i 0.01 ping
        PONG
        PONG
        每隔1秒输出内存的使用量,一共输出两次。同样的方法可以查看其它信息
        # redis-cli -r 2 -i 1 info |grep used_memory_human
        used_memory_human:52.27M
        used_memory_human:52.27M
    
  4. -x:从标准输入(STDIN)读取数据作为redis-cli的最后一个参数

        # echo 'world' | redis-cli -x set hello
        OK
    
  5. 连接redis服务器,-h服务器hostname,默认是127.0.0.1,-p端口号,-a密码,如果没有密码,不用填写

        # redis-cli -h 127.0.0.1 -p 6379 -a 123456
        127.0.0.1:6379>
    
  6. –bigkeys:使用scan命令对Redis的键进行采样,从中找出内存占比较大的键值,这些键值可能是系统瓶颈

        # redis-cli --bigkeys
        # Scanning the entire keyspace to find biggest keys as well as
        # average sizes per key type.  You can use -i 0.1 to sleep 0.1 sec
        # per 100 SCAN commands (not usually needed).
        
        [00.00%] Biggest string found so far 'hello' with 6 bytes
        
        -------- summary -------
        
        Sampled 1 keys in the keyspace!
        Total key length in bytes is 5 (avg len 5.00)
        
        Biggest string found 'hello' has 6 bytes
        
        1 strings with 6 bytes (100.00% of keys, avg size 6.00)
        0 lists with 0 items (00.00% of keys, avg size 0.00)
        0 sets with 0 members (00.00% of keys, avg size 0.00)
        0 hashs with 0 fields (00.00% of keys, avg size 0.00)
        0 zsets with 0 members (00.00% of keys, avg size 0.00)
    
  7. –pipe:管道命令,批量发送。

        # cat pipeline.txt | redis-cli --pipe
        # cat pipeline.txt | redis-cli --pipe
        All data transferred. Waiting for the last reply...
        Last reply received from server.
        errors: 0, replies: 2
    
  8. --latency:测试客户端到服务器的网络延迟。--latency-history以分时段的形式了解延迟信息(每15秒输出一次),可以通过-i控制间隔时间。--latency-dist使用统计图表的形式从控制台输出延迟统计信息

        # redis-cli --latency
        min: 0, max: 9, avg: 0.30 (32244 samples)
        # redis-cli --latency-history -i 2
        min: 0, max: 2, avg: 0.30 (187 samples) -- 2.01 seconds range
        min: 0, max: 8, avg: 0.26 (186 samples) -- 2.00 seconds range
        min: 0, max: 1, avg: 0.24 (186 samples) -- 2.00 seconds range
        # redis-cli --latency-dist
    
  9. --stat实时获取Redis的一些重要信息,--stat能实时看到一些增量信息

      # redis-cli --stat
      	------- data ------ --------------------- load -------------------- - child -
      keys       mem      clients blocked requests            connections
      3          52.27M   1       0       37124 (+0)          15
      3          52.27M   1       0       37125 (+1)          15
      3          52.27M   1       0       37126 (+1)          15
    

Redis-Server

  1. --test-memory测试当前操作系统能否稳定地分配指定容量的内存给Redis,这种检测可以有效避免因为内存问题造成Redis崩溃

     # redis-server --test-memory 1024
     ...省略...测试的时间比较长
     you memory passed this test 表示内存检测完成
    
    

Redis-benchmark

  1. redis-benchmark可以为Redis做基准性能测试,--help是帮助命令
  2. -c(clients):代表客户端的并发数量,默认50
  3. -n:代表客户端请求总量(默认100000)
  4. -q:显示request per second
  5. -r:在key、counter键上加一个12位的后缀,-r 10000表示只对后四位做随机处理(-r不是随机数的个数)
  6. -P:代表每个请求pipeline的数据量(默认1)
  7. -k:代表客户端是否使用keepalive,1为使用(默认为1),0为不使用
  8. -t:对指定命令进行基准测试
  9. 案例
  1. 10个客户端同时请求Redis,一共执行10000次,
  $ redis-benchmark -c 10 -n 10000 -r 10000 -q
  PING_INLINE: 28901.73 requests per second
  PING_BULK: 30120.48 requests per second
  SET: 29069.77 requests per second
  GET: 28901.73 requests per second
  INCR: 27777.78 requests per second
  LPUSH: 27855.15 requests per second
  RPUSH: 27548.21 requests per second
  LPOP: 28409.09 requests per second
  RPOP: 28985.51 requests per second
  SADD: 29154.52 requests per second
  HSET: 28901.73 requests per second
  SPOP: 29239.77 requests per second
  LPUSH (needed to benchmark LRANGE): 28409.09 requests per second
  LRANGE_100 (first 100 elements): 21367.52 requests per second
  LRANGE_300 (first 300 elements): 13333.33 requests per second
  LRANGE_500 (first 450 elements): 10764.26 requests per second
  LRANGE_600 (first 600 elements): 8688.10 requests per second
  MSET (10 keys): 26525.20 requests per second
  2. 查看有多少键
  redis> dbsize
  22554
  3. 对指定命令进行基准测试
  $ redis-benchmark -t get,set -q
  SET: 40080.16 requests per second
  GET: 41271.15 requests per second
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值