SLOWLOG-GET
SLOWLOG captures commands that exceeded a time threshold. Find the queries killing your performance without enabling full command logging.
You'll Learn
- Reading SLOWLOG entries
- Configuring the threshold
- Identifying slow commands
- Performance optimization tips
See Your Data, Not Terminal Text
Redimo visualizes every Redis data type beautifully. Edit inline, undo mistakes, stay safe in production.
1. What Is SLOWLOG?
Redis SLOWLOG records commands that took longer than a configurable threshold. It's a built-in profiler that runs with minimal overhead.
What It Captures
- • Timestamp of execution
- • Command and arguments
- • Execution time (microseconds)
- • Client info (Redis 4+)
What It Doesn't Include
- • Network latency
- • Queue wait time
- • Client processing time
- • Only captures slow commands
2. SLOWLOG GET: View Slow Commands
SLOWLOG GET retrieves entries from the slow log. Each entry shows what ran slowly and how long it took.
Reading SLOWLOG
# Get last 10 slow commands (default)
SLOWLOG GET 10
1) 1) (integer) 14 # Entry ID
2) (integer) 1705312245 # Unix timestamp
3) (integer) 15234 # Duration (microseconds)
4) 1) "KEYS" # Command
2) "*" # Arguments
5) "192.168.1.100:52345" # Client address
6) "myapp" # Client name (if set)
2) 1) (integer) 13
2) (integer) 1705312240
3) (integer) 8500
4) 1) "SMEMBERS"
2) "huge-set"
5) "192.168.1.101:52346"
6) "worker-1"
# Get all entries
SLOWLOG GET
# Get specific count
SLOWLOG GET 100Entry Fields
ID- Unique, incrementing identifierTimestamp- When command ran (Unix time)Duration- Microseconds (1000 = 1ms)Command- Full command with argumentsClient- IP:port and name
3. Configuration
Two settings control SLOWLOG behavior:
SLOWLOG Settings
# Check current settings
CONFIG GET slowlog-log-slower-than
1) "slowlog-log-slower-than"
2) "10000" # 10000 microseconds = 10ms
CONFIG GET slowlog-max-len
1) "slowlog-max-len"
2) "128" # Keep last 128 entries
# Set threshold to 5ms
CONFIG SET slowlog-log-slower-than 5000
# Keep more entries
CONFIG SET slowlog-max-len 1000
# Log everything (for debugging - high overhead!)
CONFIG SET slowlog-log-slower-than 0
# Disable slowlog
CONFIG SET slowlog-log-slower-than -1Threshold Tuning
4. Managing SLOWLOG
SLOWLOG Management
# Count of entries in log
SLOWLOG LEN
(integer) 42
# Clear the log
SLOWLOG RESET
OK
# Verify cleared
SLOWLOG LEN
(integer) 05. Common Slow Command Patterns
KEYS Pattern
# KEYS * scans entire keyspace - O(N)
4) 1) "KEYS"
2) "user:*"
3) (integer) 125000 # 125ms!
# Fix: Use SCAN instead
SCAN 0 MATCH user:* COUNT 100Large Collection Operations
# SMEMBERS on huge set - O(N)
4) 1) "SMEMBERS"
2) "all-users"
3) (integer) 45000 # 45ms, set has 100k members
# Fix: Use SSCAN for iteration
SSCAN all-users 0 COUNT 100
# Or reconsider data structureSorted Set Range on Large Set
# ZRANGE with large range - O(log(N) + M)
4) 1) "ZRANGEBYSCORE"
2) "leaderboard"
3) "0"
4) "+inf"
3) (integer) 85000 # 85ms, returned 50k members
# Fix: Limit results
ZRANGEBYSCORE leaderboard 0 +inf LIMIT 0 100Lua Scripts
# Long-running Lua script
4) 1) "EVALSHA"
2) "abc123..."
3) "1"
4) "mykey"
3) (integer) 200000 # 200ms!
# Review the script logic
# Consider breaking into smaller operations6. Interpreting Results
Time Ranges
< 1000 μs- Fast (<1ms)1000-10000 μs- Acceptable (1-10ms)10000-100000 μs- Slow (10-100ms)> 100000 μs- Very slow (>100ms), investigate!
Red Flags
- • Same command appearing repeatedly
- •
KEYSin any form - • Large unbounded ranges (LRANGE 0 -1)
- • Sudden spikes in duration
7. Performance Investigation Workflow
Step-by-Step
# 1. Check for recent slow commands
SLOWLOG GET 50
# 2. Identify patterns
# - Same command type?
# - Same key patterns?
# - Same client?
# 3. Get more context
SLOWLOG GET 100 | grep -i "keys\|smembers\|lrange"
# 4. Check the key
MEMORY USAGE problematic-key
DEBUG OBJECT problematic-key
TYPE problematic-key
# 5. If it's a collection, check size
SCARD problematic-set
HLEN problematic-hash
LLEN problematic-list
ZCARD problematic-zset
# 6. Correlate with latency spikes
INFO stats | grep instantaneous_ops_per_sec
INFO commandstats | grep calls8. Prevention Strategies
Replace Dangerous Commands
# Instead of KEYS
SCAN 0 MATCH pattern:* COUNT 100
# Instead of SMEMBERS on large set
SSCAN large-set 0 COUNT 100
# Instead of HGETALL on large hash
HSCAN large-hash 0 COUNT 100
# Instead of unbounded LRANGE
LRANGE list 0 99 # Limit!
# Instead of full ZRANGE
ZRANGE zset 0 99 # Limit!Command Renaming (Block Dangerous Commands)
# In redis.conf
rename-command KEYS ""
rename-command FLUSHALL ""
rename-command FLUSHDB ""
# Or rename to something obscure
rename-command KEYS "INTERNAL_KEYS_a8f3b2c1"Regular Review
9. CLI vs Redimo
CLI Output
1) 1) (integer) 14
2) (integer) 1705312245
3) (integer) 15234
4) 1) "EVALSHA"
2) "abc123def456789..."
3) "3"
4) "{user:1001}:profile"
5) "{user:1001}:settings"
5) "192.168.1.100:52345"
6) "myapp"
# Hard to scan, compare, or filterWhat Would Help
- • Table view with sortable columns
- • Human-readable timestamps
- • Duration in ms instead of μs
- • Filter by command type
- • Trend visualization over time
Quick Reference
| Command | Purpose |
|---|---|
SLOWLOG GET [n] | Get last n slow entries |
SLOWLOG LEN | Count of log entries |
SLOWLOG RESET | Clear the log |
slowlog-log-slower-than | Threshold in microseconds |
slowlog-max-len | Max entries to keep |
Find Your Slow Commands
Performance issues hide in plain sight. SLOWLOG reveals them. Debug faster with Redimo.
Download Redimo - It's Free