我爱编程

Redis shell 常用命令

2017-08-06  本文已影响284人  非典型程序员

redis-server 详解

  1. --test-memory
    检测当前操作系统能否稳定地分配指定容量的内存给 Redis,通过这种检测可以有效避免因为内存问题造成 Redis 崩溃,当输出 passed this test 时说明内存检测完毕。 如检查当前系统是否能给redis分配 2G 的内存:

    [root@iZu1qhttxe5Z conf] redis-server --test-memory 2048  
    ·······
    Please keep the test running several minutes per GB of memory.
    Also check http://www.memtest86.com/ and http://pyropus.ca/software/memtester/
    
    Your memory passed this test.
    Please if you are still in doubt use the following two tools:
    1) memtest86: http://www.memtest86.com/
    2) memtester: http://pyropus.ca/software/memtester/
    [root@iZu1qhttxe5Z conf]
    

redis-cli 详解

  1. -r
    -r(repeat)选项代表将命令执行多次,例如下面操作将会执行三次 ping 命令:

     [root@iZu1qhttxe5Z ~]# redis-cli -r 3  ping
     PONG
     PONG
     PONG
     [root@iZu1qhttxe5Z ~]# 
    
  2. -i
    -i(interval) 选项代表每隔几秒执行一次命令,但是 -i 选项必须和 -r 选项一起使
    用,下面的操作会每隔 2秒执行一次 ping 命令,一共执行 6 次:

    [root@iZu1qhttxe5Z ~]# redis-cli -r 6 -i 2  ping
    PONG
    PONG
    PONG
    PONG
    PONG
    PONG
    

    -i 的单位是秒,不支持毫秒为单位,但是如果想以每隔 10 毫秒执行一次,可以用 -i 0.01,例如:redis-cli -r 5 -i 0.01 ping

  3. -x
    -x 选项代表从标准输入(stdin)读取数据作为 redis-cli 的最后一个参数,例如下面
    的操作会将字符串 world 作为 set hello 的值:

    [root@iZu1qhttxe5Z ~]# echo -n  "nyr" | redis-cli -x  set mylove # -n 参数指定 echo输出不换行
    OK
    [root@iZu1qhttxe5Z ~]# redis-cli get mylove
    "nyr"
    [root@iZu1qhttxe5Z ~]#
    
  4. . --raw 和 --no-raw
    --no-raw 选项是要求命令的返回结果必须是原始的格式,--raw 恰恰相反,返回格式化后的结果

    [root@iZu1qhttxe5Z conf]# redis-cli set hello "你好"
    OK
    [root@iZu1qhttxe5Z conf]# redis-cli get hello
    "\xe4\xbd\xa0\xe5\xa5\xbd"
    [root@iZu1qhttxe5Z conf]# redis-cli --no-raw get hello
    "\xe4\xbd\xa0\xe5\xa5\xbd"
    [root@iZu1qhttxe5Z conf]# redis-cli --raw get hello
    你好
    [root@iZu1qhttxe5Z conf]# 
    
  5. --stat
    --stat 选项可以实时获取 Redis 的重要统计信息.

    [root@iZu1qhttxe5Z conf]# redis-cli --stat
    ------- data ------ --------------------- load -------------------- - child -
    keys       mem      clients blocked requests            connections          
    4          792.44K  1       0       26 (+0)             8           
    4          792.44K  1       0       27 (+1)             8           
    
  6. bgsvae /save
    bgsvae / save, 命令将在 redis 数据目录中创建dump.rdb文件,bgsvae 在后台执行。

    [root@iZu1qhttxe5Z data]# redis-cli bgsave
    Background saving started
    [root@iZu1qhttxe5Z data]# ls
    dump-6379.rdb
    
  7. config get dir 获取 redis 数据目录。

    [root@iZu1qhttxe5Z data]# redis-cli config get dir
    1) "dir"
    2) "/opt/redis-sentinel/data"
    [root@iZu1qhttxe5Z data]# 
    
  8. --slave
    --slave 选项是把当前客户端模拟成当前 Redis 节点的从节点,可以用来获取当前
    Redis 节点的更新操作。

  9. --bigkeys
    --bigkeys 选项使用 scan 命令对 Redis 的键进行采样,从中找到内存占用比较大的
    键值,这些键可能是系统的瓶颈。

上一篇 下一篇

猜你喜欢

热点阅读