?
本文檔使用 PHP中文網(wǎng)手冊(cè) 發(fā)布
MONITOR
自1.0.0起可用。
MONITOR 是一個(gè)調(diào)試命令,用于回傳 Redis 服務(wù)器處理的每個(gè)命令。它可以幫助理解數(shù)據(jù)庫正在發(fā)生的事情。該命令可以通過redis-cli
和通過使用telnet
。
查看服務(wù)器處理的所有請(qǐng)求的能力對(duì)于在使用 Redis 作為數(shù)據(jù)庫和分布式緩存系統(tǒng)時(shí)都能發(fā)現(xiàn)應(yīng)用程序中的錯(cuò)誤很有用。
$ 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 )停止正在運(yùn)行的 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.
手動(dòng)發(fā)出 QUIT 命令以停止運(yùn)行的 MONITOR 流telnet
。
出于安全考慮,某些特殊的管理命令CONFIG
不會(huì)登錄到 MONITOR 輸出中。
由于 MONITOR 將所有命令傳回,因此其使用需要付出代價(jià)。下面的(完全不科學(xué)的)基準(zhǔn)數(shù)字說明了 MONITOR 的運(yùn)行成本。
未運(yùn)行 MONITOR 的基準(zhǔn)測(cè)試結(jié)果:
$ 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
基準(zhǔn)測(cè)試結(jié)果與監(jiān)視正在運(yù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
在這種特殊情況下,運(yùn)行單個(gè) MONITOR 客戶端可以將吞吐量降低50%以上。運(yùn)行更多的 MONITOR 客戶端將進(jìn)一步降低吞吐量。
非標(biāo)準(zhǔn)返回值,只是將接收到的命令轉(zhuǎn)儲(chǔ)為無限流。