Difficulty: Intermediate
What is the Redis SLOWLOG, how do you configure it, and how would you use it to debug latency?
SLOWLOG is an in-memory log of commands whose execution time exceeded a threshold, set by slowlog-log-slower-than in microseconds (default 10,000, which is 10 ms). You read it with SLOWLOG GET, and each entry tells you the command, its arguments, how long it ran and which client sent it. Because Redis runs commands on a single thread, one slow command delays every other client, so the slowlog is the first place to look when latency spikes.
SLOWLOG GET [count] returns the most recent entries first (10 by default). Each entry has:
ip:port.CLIENT SETNAME.SLOWLOG LEN returns how many entries are stored, and SLOWLOG RESET clears them.
The duration is pure execution time inside Redis. It does not include network round trips, time spent waiting in the queue behind other commands, or the time to read the request and write the reply. So a client can see 200 ms latency while the slowlog is empty. In that case the cause is elsewhere: network issues, a fork for BGSAVE, swapping, or a client sending thousands of commands without pipelining. For those, use LATENCY DOCTOR and the latency monitor (enable it with latency-monitor-threshold).
| Setting | Default | Meaning |
|---|---|---|
slowlog-log-slower-than | 10000 | Threshold in microseconds. 0 logs every command, a negative value disables logging. |
slowlog-max-len | 128 | Number of entries kept. Oldest entries are dropped once full. |
On a busy production cache, many teams lower the threshold to 1,000 to 5,000 microseconds and raise slowlog-max-len to 1,000 or more. The log lives in memory, so even a few thousand entries cost very little.
KEYS * on a large keyspace. Replace it with SCAN.HGETALL, SMEMBERS or LRANGE 0 -1 on a big key with hundreds of thousands of elements.DEL on a huge collection. Use UNLINK, which frees memory in a background thread.SORT, ZUNIONSTORE or SUNION over large sets.A real workflow: an orders service at peak shows p99 latency jumping from 2 ms to 80 ms. SLOWLOG GET 20 shows HGETALL cart:* calls taking 40 ms each because some carts store full product JSON. The fix is to fetch only needed fields with HMGET and keep payloads small. Then run redis-cli --bigkeys or --memkeys to find other oversized keys before they cause the next incident.
# Log anything slower than 5 ms and keep 1000 entries
redis-cli CONFIG SET slowlog-log-slower-than 5000
redis-cli CONFIG SET slowlog-max-len 1000
# Show the 2 most recent slow commands
redis-cli SLOWLOG GET 2
# How many entries are stored, then clear after investigating
redis-cli SLOWLOG LEN
redis-cli SLOWLOG RESET
Entry 412 shows an HGETALL that took about 42 ms from the orders-api service. Entry 411 is a KEYS call from an unnamed client, which should be replaced with SCAN.
SLOWLOG, slowlog-log-slower-than, slowlog-max-len, Latency, Big Keys