The slow log helps find commands that take a long time to run in Redis. This helps you see what makes your database slow.
Slow log for performance analysis in Redis
SLOWLOG GET [count] SLOWLOG LEN SLOWLOG RESET
SLOWLOG GET [count] shows the slow commands, optionally limited by count.
SLOWLOG LEN shows how many slow log entries are stored.
SLOWLOG RESET clears all slow log entries.
SLOWLOG GET 5SLOWLOG LEN
SLOWLOG RESET
This example clears the slow log, sets the threshold to 10 milliseconds, runs a fast command (PING), then a slow command (DEBUG SLEEP 0.02), and finally gets the last 2 slow log entries.
SLOWLOG RESET CONFIG SET slowlog-log-slower-than 10000 PING DEBUG SLEEP 0.02 SLOWLOG GET 2
The slow log records commands that take longer than the configured threshold (in microseconds).
By default, the slow log threshold is 10,000 microseconds (10 ms).
Use CONFIG SET slowlog-log-slower-than 0 to log all commands.
The slow log helps find slow commands in Redis.
You can view, count, and clear slow log entries.
Adjust the threshold to control what is logged.
Practice
Solution
Step 1: Understand what slow log tracks
The slow log records commands that exceed a certain execution time threshold.Step 2: Differentiate from other Redis features
It does not store all commands, clear cache, or backup data; it only logs slow commands.Final Answer:
To record commands that take longer than a set time to execute -> Option CQuick Check:
Slow log = records slow commands [OK]
- Thinking slow log stores all commands
- Confusing slow log with cache clearing
- Assuming slow log is for backups
Solution
Step 1: Recall the Redis slow log retrieval command
The official command to get slow log entries isSLOWLOG GET.Step 2: Verify other options
Commands likeSLOWLOG FETCH,SLOWLOG SHOW, andSLOWLOG LISTdo not exist in Redis.Final Answer:
SLOWLOG GET -> Option DQuick Check:
Retrieve slow log = SLOWLOG GET [OK]
- Using non-existent commands like SLOWLOG FETCH
- Confusing with LIST or SHOW commands
- Misspelling the command
SLOWLOG RESET SLOWLOG LEN SLOWLOG GET 2
What will be the output of
SLOWLOG LEN immediately after the reset?Solution
Step 1: Understand SLOWLOG RESET effect
TheSLOWLOG RESETcommand clears all slow log entries, so the log becomes empty.Step 2: Check SLOWLOG LEN after reset
Since the log is empty,SLOWLOG LENreturns 0, indicating no entries.Final Answer:
0 -> Option AQuick Check:
Reset clears log, length = 0 [OK]
- Expecting old entries after reset
- Confusing SLOWLOG LEN with SLOWLOG GET output
- Thinking reset causes error
SLOWLOG GET but receive an empty list even though you expect slow commands. What is the most likely cause?Solution
Step 1: Understand slow log threshold role
Redis only logs commands slower than the configured threshold (default 10ms). If threshold is too high, no commands get logged.Step 2: Eliminate other causes
Redis server down would cause connection errors, not empty logs. Restart is not needed to enable slow log. Slow log size is limited but overwrites old entries, so it won't be empty due to fullness.Final Answer:
The slow log threshold is set too high, so no commands qualify -> Option AQuick Check:
High threshold = no slow commands logged [OK]
- Assuming Redis must restart to enable slow log
- Thinking slow log fills up and stops logging
- Confusing server down with empty slow log
Solution
Step 1: Set threshold to 50 milliseconds
Redis uses microseconds, so 50 ms = 50000 μs. UseCONFIG SET slowlog-log-slower-than 50000. A and C correct; B and D use 50 μs (too low).Step 2: Limit slow log length to 5 entries
UseCONFIG SET slowlog-max-len 5. Only A and D do this; B and C do not.Step 3: Reset slow log and get last 5 entries
SLOWLOG RESETclears old entries;SLOWLOG GET 5retrieves last 5. All options include this.Step 4: Choose correct option
Only A sets both max-len to 5 and threshold to 50000 μs (50 ms).Final Answer:
CONFIG SET slowlog-max-len 5 CONFIG SET slowlog-log-slower-than 50000 SLOWLOG RESET SLOWLOG GET 5 -> Option BQuick Check:
Threshold 50ms = 50000μs, max len 5, reset, get 5 [OK]
- Confusing milliseconds with microseconds in threshold
- Not setting max length to limit entries
- Forgetting to reset slow log before analysis
Ready to prove it?
Pass the test and this pattern moves unknown
