?
This document uses PHP Chinese website manual Release
MONITOR
自1.0.0起可用。
MONITOR 是一個調試命令,用于回傳 Redis 服務器處理的每個命令。它可以幫助理解數據庫正在發(fā)生的事情。該命令可以通過redis-cli
和通過使用telnet
。
查看服務器處理的所有請求的能力對于在使用 Redis 作為數據庫和分布式緩存系統(tǒng)時都能發(fā)現應用程序中的錯誤很有用。
$ redis-cli monitor 1339518083.107412 [0 127.0.0.1:60866] "keys" "*" 1339518087.877697 [0 127.0.0.1:60866] "dbsize" 1339518090.420270 [0 127.0.0.1:60866] "set" "x" "6" 1339518096.506257 [0 127.0.0.1:60866] "get" "x" 1339518099.363765 [0 127.0.0.1:60866] "del" "x" 1339518100.544926 [0 127.0.0.1:60866] "get" "x"
使用SIGINT
( Ctrl-C )停止正在運行的 MONITOR 流redis-cli
。
$ telnet localhost 6379 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. MONITOR +OK +1339518083.107412 [0 127.0.0.1:60866] "keys" "*" +1339518087.877697 [0 127.0.0.1:60866] "dbsize" +1339518090.420270 [0 127.0.0.1:60866] "set" "x" "6" +1339518096.506257 [0 127.0.0.1:60866] "get" "x" +1339518099.363765 [0 127.0.0.1:60866] "del" "x" +1339518100.544926 [0 127.0.0.1:60866] "get" "x" QUIT +OK Connection closed by foreign host.
手動發(fā)出 QUIT 命令以停止運行的 MONITOR 流telnet
。
出于安全考慮,某些特殊的管理命令CONFIG
不會登錄到 MONITOR 輸出中。
由于 MONITOR 將所有命令傳回,因此其使用需要付出代價。下面的(完全不科學的)基準數字說明了 MONITOR 的運行成本。
未運行 MONITOR 的基準測試結果:
$ src/redis-benchmark -c 10 -n 100000 -q PING_INLINE: 101936.80 requests per second PING_BULK: 102880.66 requests per second SET: 95419.85 requests per second GET: 104275.29 requests per second INCR: 93283.58 requests per second
基準測試結果與監(jiān)視正在運行的(redis-cli monitor > /dev/null
):
$ src/redis-benchmark -c 10 -n 100000 -q PING_INLINE: 58479.53 requests per second PING_BULK: 59136.61 requests per second SET: 41823.50 requests per second GET: 45330.91 requests per second INCR: 41771.09 requests per second
在這種特殊情況下,運行單個 MONITOR 客戶端可以將吞吐量降低50%以上。運行更多的 MONITOR 客戶端將進一步降低吞吐量。
非標準返回值,只是將接收到的命令轉儲為無限流。