Latest web development tutorials

Redis Showlog 命令

Redis服務器

Redis Showlog 是Redis 用來記錄查詢執行時間的日誌系統。

查詢執行時間指的是不包括像客戶端響應(talking)、發送回復等IO 操作,而單單是執行一個查詢命令所耗費的時間。

另外,slow log 保存在內存裡面,讀寫速度非常快,因此你可以放心地使用它,不必擔心因為開啟slow log 而損害Redis 的速度。

語法

redis Showlog 命令基本語法如下:

redis 127.0.0.1:6379> SLOWLOG subcommand [argument]

可用版本

>= 2.2.12

返回值

取決於不同命令,返回不同的值。

實例

查看日誌信息:

redis 127.0.0.1:6379> slowlog get 2
1) 1) (integer) 14
   2) (integer) 1309448221
   3) (integer) 15
   4) 1) "ping"
2) 1) (integer) 13
   2) (integer) 1309448128
   3) (integer) 30
   4) 1) "slowlog"
      2) "get"
      3) "100"

查看當前日誌的數量:

redis 127.0.0.1:6379> SLOWLOG LEN
(integer) 14

使用命令SLOWLOG RESET 可以清空slow log 。

redis 127.0.0.1:6379> SLOWLOG LEN
(integer) 14

redis 127.0.0.1:6379> SLOWLOG RESET
OK

redis 127.0.0.1:6379> SLOWLOG LEN
(integer) 0

Redis服務器