Redis常用命令解析——INFO, MONITOR, SLOWLOG,redisslowlog

來源:互聯網
上載者:User

Redis常用命令解析——INFO, MONITOR, SLOWLOG,redisslowlog

  作者:zhanhailiang 日期:2014-12-02

1. INFO

info指令返回伺服器相關資訊,包括:

  • server: General information about the Redis server
  • clients: Client connections section
  • memory: Memory consumption related information
  • persistence: RDB and AOF related information
  • stats: General statistics
  • replication: Master/slave replication information
  • cpu: CPU consumption statistics
  • commandstats: Redis command statistics
  • cluster: Redis Cluster section
  • keyspace: Database related statistics

其本身支援定製返回列表:

[root@~]# redis-cli info[root@~]# redis-cli info default[root@~]# redis-cli info all

詳情請見:http://www.redis.cn/commands/info.html

2. MONITOR

MONITOR是一個調試命令,返回伺服器處理的每一個命令,它能協助我們瞭解在資料庫上發生了什麼操作。共有3種操作方法:

[root@~]# redis-cli monitorOK1417532512.619715 [0 127.0.0.1:55043] "REPLCONF" "ACK" "6623624"[root@~]# telnet 127.0.0.1 6379Trying 127.0.0.1...Connected to 127.0.0.1.Escape character is '^]'.monitor+OK+1417532567.733458 [0 127.0.0.1:55043] "REPLCONF" "ACK" "6623708"+1417532568.735936 [0 127.0.0.1:55043] "REPLCONF" "ACK" "6623708"quit+OKConnection closed by foreign host.[root@~]# redis-cli 127.0.0.1:6379> monitorOK1417532590.785487 [0 127.0.0.1:55043] "REPLCONF" "ACK" "6623736"

由於MONITOR命令返回伺服器處理的所有的命令, 所以在效能上會有一些消耗。使用官方的壓測工具測試結果如下

在不運行MONITOR命令的情況下,benchmark的測試結果:

[root@~/software/redis-2.8.17]# src/redis-benchmark -c 10 -n 100000 -qPING_INLINE: 51020.41 requests per secondPING_BULK: 50607.29 requests per secondSET: 37257.82 requests per secondGET: 49800.80 requests per secondINCR: 38699.69 requests per secondLPUSH: 38910.51 requests per secondLPOP: 39277.30 requests per secondSADD: 54614.96 requests per secondSPOP: 51948.05 requests per secondLPUSH (needed to benchmark LRANGE): 38819.88 requests per secondLRANGE_100 (first 100 elements): 20112.63 requests per secondLRANGE_300 (first 300 elements): 9025.27 requests per secondLRANGE_500 (first 450 elements): 6836.67 requests per secondLRANGE_600 (first 600 elements): 5406.28 requests per secondMSET (10 keys): 19394.88 requests per second

在運行MONITOR命令的情況下,benchmark的測試結果: (redis-cli monitor > /dev/null):

[root@~/software/redis-2.8.17]# src/redis-benchmark -c 10 -n 100000 -qPING_INLINE: 42211.91 requests per secondPING_BULK: 42936.88 requests per secondSET: 26143.79 requests per secondGET: 33990.48 requests per secondINCR: 26553.37 requests per secondLPUSH: 27337.34 requests per secondLPOP: 27225.70 requests per secondSADD: 30459.95 requests per secondSPOP: 39494.47 requests per secondLPUSH (needed to benchmark LRANGE): 26315.79 requests per secondLRANGE_100 (first 100 elements): 22055.58 requests per secondLRANGE_300 (first 300 elements): 8104.38 requests per secondLRANGE_500 (first 450 elements): 6371.05 requests per secondLRANGE_600 (first 600 elements): 5031.95 requests per secondMSET (10 keys): 14861.05 requests per second

可以看到各項指標基本都有所下降。

詳情請見:http://www.redis.cn/commands/monitor.html

3. SLOWLOG

通過SLOWLOG可以讀取慢查詢日誌。

使用SLOWLOG LEN就可以擷取當前慢日誌長度。

[root@~/software/redis-2.8.17]# redis-cli 127.0.0.1:6379> slowlog len(integer) 28

使用SLOWLOG GET就可以擷取所有慢日誌。

127.0.0.1:6379> slowlog get  1) 1) (integer) 27    2) (integer) 1417531320    3) (integer) 24623    4) 1) "info"

其中,各項指標表示:

  • A unique progressive identifier for every slow log entry.
  • The unix timestamp at which the logged command was processed.
  • The amount of time needed for its execution, in microseconds(注意,microseconds翻譯成微秒,而不是毫秒).
  • The array composing the arguments of the command.

使用SLOWLOG GET N就可以擷取最近N條慢日誌。

127.0.0.1:6379> slowlog get 21) 1) (integer) 27   2) (integer) 1417531320   3) (integer) 24623   4) 1) "info"2) 1) (integer) 26   2) (integer) 1417528379   3) (integer) 21363   4) 1) "get"      2) "user:score"

使用SLOWLOG RESET命令重設慢日誌。一旦執行,將丟失以前的所有慢日誌。

127.0.0.1:6379> slowlog reset

詳情請見:http://www.redis.cn/commands/slowlog.html

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.