MONITOR, SLOWLOG & Latency Debugging
Watch every command in real time and find slow queries.
Code
# MONITOR streams every command executed by the server (ALL clients)
$ redis-cli MONITOR
OK
1748200000.123456 [0 127.0.0.1:54321] "SET" "foo" "bar"
1748200000.234567 [0 127.0.0.1:54322] "GET" "foo"
# SLOWLOG — commands exceeding slowlog-log-slower-than (default 10ms)
127.0.0.1:6379> CONFIG GET slowlog-log-slower-than
127.0.0.1:6379> CONFIG SET slowlog-log-slower-than 5000 # 5ms (microseconds)
127.0.0.1:6379> SLOWLOG GET 10 # last 10 slow entries
127.0.0.1:6379> SLOWLOG RESET
# Latency monitoring (Redis 7+)
127.0.0.1:6379> CONFIG SET latency-monitor-threshold 100 # ms
127.0.0.1:6379> LATENCY HISTORY event
127.0.0.1:6379> LATENCY GRAPH event
# Per-command stats (Redis 7+)
127.0.0.1:6379> INFO commandstats
# cmdstat_get:calls=1234,usec=5678,usec_per_call=4.60,rejected_calls=0,failed_calls=0
# Check what's blocking the server
127.0.0.1:6379> INFO clients
127.0.0.1:6379> CLIENT NO-EVICT on # protect this client from evictionExplanation
MONITOR streams every command processed by the server, prefixed with timestamp, DB, and client — invaluable for debugging but a performance hit, so don't leave it on in production. SLOWLOG records commands slower than slowlog-log-slower-than (in microseconds; 0 logs everything, negative disables). SLOWLOG GET N shows entries; SLOWLOG RESET clears. For deeper latency work, set latency-monitor-threshold and use LATENCY HISTORY/GRAPH to visualize events. INFO commandstats reveals per-command call counts and average micros — great for spotting hot keys or N+1 patterns.
More Redis CLI Snippets
Connecting: URLs, TLS, AUTH & Select
Connect to standalone, TLS, authenticated, or non-default DB indexes.
Interactive Mode, HELP & Inspecting
Navigate the REPL, discover commands, and introspect the server.
MULTI / EXEC / WATCH (Transactions)
Queue commands atomically and use optimistic locking with WATCH.
Pub/Sub: SUBSCRIBE, PUBLISH & PSUBSCRIBE
Fan-out messaging with channels and pattern subscriptions.
EVAL, Lua & Function Stats (Server-side Scripting)
Run atomic server-side Lua scripts; load and call functions.
RDB / AOF Persistence & Backup
Trigger snapshots, manage AOF rewrite, and capture a safe backup.