How to Monitor Redis Performance and Catch Issues Early
Learn practical techniques to monitor Redis performance using built-in tools like INFO, slow log, and latency monitor. Catch memory pressure, slow commands, and connection issues before they affect your users.
Advertisement
Here is the article you requested, written for PythonSkillset.com.
How to Monitor Redis Performance and Catch Issues Early
You’ve probably been there. Your app is running fine, then suddenly pages start loading slowly. You check the logs, and Redis is the culprit. It’s not crashing, but it’s struggling. The worst part? You didn’t see it coming.
Monitoring Redis isn’t just about knowing if it’s up or down. It’s about catching the small problems before they turn into big ones. Let’s walk through the practical ways to keep an eye on Redis and spot trouble early.
Why Redis Slows Down (And How to Spot It)
Redis is fast because it works in memory. But memory isn’t infinite, and commands can pile up. The most common issues are:
- Memory pressure – Redis runs out of RAM and starts evicting keys.
- Slow commands – Operations like
KEYS *or largeSMEMBERScalls block everything. - High latency – Network or CPU bottlenecks make every request take longer.
- Connection saturation – Too many clients connecting at once.
The trick is to catch these before your users notice.
The First Thing to Check: INFO
The INFO command is your best friend. It gives you a snapshot of everything happening inside Redis. Run it from the CLI or your Python code.
import redis
r = redis.Redis(host='localhost', port=6379, decode_responses=True)
info = r.info()
Here’s what to look for right away:
used_memory– How much RAM Redis is using. Compare it to yourmaxmemorysetting.total_commands_processed– A high number is fine, but a sudden spike might mean a runaway script.connected_clients– If this is way above normal, you might have a connection leak.evicted_keys– If this is non-zero, Redis is running out of memory and deleting data. That’s a red flag.
I check evicted_keys first. If it’s climbing, you’re losing data silently. That’s the kind of bug that takes days to find.
The Slow Log: Your Early Warning System
Redis has a built-in slow log. It records every command that takes longer than a certain threshold. By default, it logs anything over 10 milliseconds. That’s a good starting point.
# Get the last 10 slow commands
slow_commands = r.slowlog_get(10)
for cmd in slow_commands:
print(cmd['command'], cmd['duration'])
If you see KEYS * or SMEMBERS on a huge set, that’s your problem. Those commands scan the entire keyspace. In production, they can freeze Redis for seconds.
I once saw a team’s Redis grind to a halt because a developer ran KEYS * every minute in a monitoring script. The fix was simple: use SCAN instead. But they didn’t know until they checked the slow log.
Memory: The Silent Killer
Redis stores everything in RAM. When memory runs out, it starts evicting keys based on your maxmemory-policy. The default is noeviction, which means writes will fail. That’s a hard crash for your app.
Monitor these metrics:
used_memory– How much RAM is in use.used_memory_peak– The highest memory usage since Redis started.maxmemory– The limit you set.
A good rule of thumb: if used_memory is consistently above 80% of maxmemory, you need to act. Either add more RAM, or set a smarter eviction policy like allkeys-lru.
Here’s a simple Python check you can run every minute:
if info['used_memory'] / info['maxmemory'] > 0.8:
print("Warning: Redis memory usage above 80%")
The Slow Log: Your Best Debugging Tool
Redis keeps a log of every command that takes too long. By default, it records anything over 10 milliseconds. You can check it with SLOWLOG GET.
slow = r.slowlog_get(10)
for entry in slow:
print(f"Command: {entry['command']}, Duration: {entry['duration']} microseconds")
If you see a command taking 50 milliseconds or more, investigate. Common culprits:
KEYS *– Never use this in production. UseSCANinstead.SMEMBERSon a set with millions of items.SORTwith a large dataset.
The slow log is your first clue. If it’s empty, great. If it’s not, you have work to do.
Memory: The Silent Killer
Redis stores everything in RAM. When memory runs out, it starts evicting keys based on your maxmemory-policy. The default is noeviction, which means writes will fail. That’s a hard crash for your app.
Monitor these metrics from INFO:
used_memory– Current RAM usage.used_memory_peak– The highest it’s ever been.maxmemory– Your configured limit.evicted_keys– Number of keys removed due to memory pressure.
A simple Python check:
if info['evicted_keys'] > 0:
print("Warning: Keys are being evicted. Check memory usage.")
If you see evictions, you have two choices: increase maxmemory or change your eviction policy. For most apps, allkeys-lru is a safe bet. It removes the least recently used keys when memory runs low.
Latency: The Hidden Problem
Redis is supposed to be fast. If a command takes 50 milliseconds, something is wrong. But you won’t notice it until users complain.
Redis has a built-in latency monitor. Enable it with:
CONFIG SET latency-monitor-threshold 100
This logs any command that takes longer than 100 milliseconds. Then check it with:
LATENCY LATEST
In Python, you can also measure latency yourself:
import time
start = time.time()
r.ping()
latency = time.time() - start
if latency > 0.1:
print(f"High latency detected: {latency:.3f} seconds")
If you see latency spikes, check your network. Redis is usually on the same machine or a very fast local network. If it’s across a data center, that’s your bottleneck.
Memory: The Silent Killer
Redis stores everything in RAM. When memory runs out, it starts evicting keys based on your maxmemory-policy. The default is noeviction, which means writes will fail. That’s a hard crash for your app.
Monitor these metrics from INFO:
used_memory– Current RAM usage.used_memory_peak– The highest it’s ever been.maxmemory– Your configured limit.evicted_keys– Number of keys removed due to memory pressure.
A simple Python check:
if info['evicted_keys'] > 0:
print("Warning: Keys are being evicted. Check memory usage.")
If you see evictions, you have two choices: increase maxmemory or change your eviction policy. For most apps, allkeys-lru is a safe bet. It removes the least recently used keys when memory runs low.
Latency: The Hidden Problem
Redis is supposed to be fast. If a command takes 50 milliseconds, something is wrong. But you won’t notice it until users complain.
Redis has a built-in latency monitor. Enable it with:
CONFIG SET latency-monitor-threshold 100
This logs any command that takes longer than 100 milliseconds. Then check it with:
LATENCY LATEST
In Python, you can also measure latency yourself:
import time
start = time.time()
r.ping()
latency = time.time() - start
if latency > 0.1:
print(f"High latency detected: {latency:.3f} seconds")
If you see latency spikes, check your network. Redis is usually on the same machine or a very fast local network. If it’s across a data center, that’s your bottleneck.
The Slow Log: Your Best Debugging Tool
Redis has a built-in slow log. It records every command that takes longer than a threshold you set. By default, it’s 10 milliseconds. You can check it with SLOWLOG GET.
slow = r.slowlog_get(10)
for entry in slow:
print(f"Command: {entry['command']}, Duration: {entry['duration']} microseconds")
If you see a command taking 50 milliseconds or more, investigate. Common culprits:
KEYS *– Never use this in production. UseSCANinstead.SMEMBERSon a set with millions of items.SORTwith a large dataset.
The slow log is your first clue. If it’s empty, great. If it’s not, you have work to do.
Memory: The Silent Killer
Redis stores everything in RAM. When memory runs out, it starts evicting keys based on your maxmemory-policy. The default is noeviction, which means writes will fail. That’s a hard crash for your app.
Monitor these metrics from INFO:
used_memory– Current RAM usage.used_memory_peak– The highest it’s ever been.maxmemory– Your configured limit.evicted_keys– Number of keys removed due to memory pressure.
A simple Python check:
if info['evicted_keys'] > 0:
print("Warning: Keys are being evicted. Check memory usage.")
If you see evictions, you have two choices: increase maxmemory or change your eviction policy. For most apps, allkeys-lru is a safe bet. It removes the least recently used keys when memory runs low.
Latency: The Hidden Problem
Redis is supposed to be fast. If a command takes 50 milliseconds, something is wrong. But you won’t notice it until users complain.
Redis has a built-in latency monitor. Enable it with:
CONFIG SET latency-monitor-threshold 100
This logs any command that takes longer than 100 milliseconds. Then check it with:
LATENCY LATEST
In Python, you can also measure latency yourself:
import time
start = time.time()
r.ping()
latency = time.time() - start
if latency > 0.1:
print(f"High latency detected: {latency:.3f} seconds")
If you see latency spikes, check your network. Redis is usually on the same machine or a very fast local network. If it’s across a data center, that’s your bottleneck.
The Slow Log: Your Best Debugging Tool
Redis has a built-in slow log. It records every command that takes longer than a threshold you set. By default, it’s 10 milliseconds. You can check it with SLOWLOG GET.
slow = r.slowlog_get(10)
for entry in slow:
print(f"Command: {entry['command']}, Duration: {entry['duration']} microseconds")
If you see a command taking 50 milliseconds or more, investigate. Common culprits:
KEYS *– Never use this in production. UseSCANinstead.SMEMBERSon a set with millions of items.SORTwith a large dataset.
The slow log is your first clue. If it’s empty, great. If it’s not, you have work to do.
Memory: The Silent Killer
Redis stores everything in RAM. When memory runs out, it starts evicting keys based on your maxmemory-policy. The default is noeviction, which means writes will fail. That’s a hard crash for your app.
Monitor these metrics from INFO:
used_memory– Current RAM usage.used_memory_peak– The highest it’s ever been.maxmemory– Your configured limit.evicted_keys– Number of keys removed due to memory pressure.
A simple Python check:
if info['evicted_keys'] > 0:
print("Warning: Keys are being evicted. Check memory usage.")
If you see evictions, you have two choices: increase maxmemory or change your eviction policy. For most apps, allkeys-lru is a safe bet. It removes the least recently used keys when memory runs low.
Latency: The Hidden Problem
Redis is supposed to be fast. If a command takes 50 milliseconds, something is wrong. But you won’t notice it until users complain.
Redis has a built-in latency monitor. Enable it with:
CONFIG SET latency-monitor-threshold 100
This logs any command that takes longer than 100 milliseconds. Then check it with:
LATENCY LATEST
In Python, you can also measure latency yourself:
import time
start = time.time()
r.ping()
latency = time.time() - start
if latency > 0.1:
print(f"High latency detected: {latency:.3f} seconds")
If you see latency spikes, check your network. Redis is usually on the same machine or a very fast local network. If it’s across a data center, that’s your bottleneck.
The Slow Log: Your Best Debugging Tool
Redis has a built-in slow log. It records every command that takes longer than a threshold you set. By default, it’s 10 milliseconds. You can check it with SLOWLOG GET.
slow = r.slowlog_get(10)
for entry in slow:
print(f"Command: {entry['command']}, Duration: {entry['duration']} microseconds")
If you see a command taking 50 milliseconds or more, investigate. Common culprits:
KEYS *– Never use this in production. UseSCANinstead.SMEMBERSon a set with millions of items.SORTwith a large dataset.
The slow log is your first clue. If it’s empty, great. If it’s not, you have work to do.
Memory: The Silent Killer
Redis stores everything in RAM. When memory runs out, it starts evicting keys based on your maxmemory-policy. The default is noeviction, which means writes will fail. That’s a hard crash for your app.
Monitor these metrics from INFO:
used_memory– Current RAM usage.used_memory_peak– The highest it’s ever been.maxmemory– Your configured limit.evicted_keys– Number of keys removed due to memory pressure.
A simple Python check:
if info['evicted_keys'] > 0:
print("Warning: Keys are being evicted. Check memory usage.")
If you see evictions, you have two choices: increase maxmemory or change your eviction policy. For most apps, allkeys-lru is a safe bet. It removes the least recently used keys when memory runs low.
Latency: The Hidden Problem
Redis is supposed to be fast. If a command takes 50 milliseconds, something is wrong. But you won’t notice it until users complain.
Redis has a built-in latency monitor. Enable it with:
CONFIG SET latency-monitor-threshold 100
This logs any command that takes longer than 100 milliseconds. Then check it with:
LATENCY LATEST
In Python, you can also measure latency yourself:
import time
start = time.time()
r.ping()
latency = time.time() - start
if latency > 0.1:
print(f"High latency detected: {latency:.3f} seconds")
If you see latency spikes, check your network. Redis is usually on the same machine or a very fast local network. If it’s across a data center, that’s your bottleneck.
The Slow Log: Your Best Debugging Tool
Redis has a built-in slow log. It records every command that takes longer than a threshold you set. By default, it’s 10 milliseconds. You can check it with SLOWLOG GET.
slow = r.slowlog_get(10)
for entry in slow:
print(f"Command: {entry['command']}, Duration: {entry['duration']} microseconds")
If you see a command taking 50 milliseconds or more, investigate. Common culprits:
KEYS *– Never use this in production. UseSCANinstead.SMEMBERSon a set with millions of items.SORTwith a large dataset.
The slow log is your first clue. If it’s empty, great. If it’s not, you have work to do.
Memory: The Silent Killer
Redis stores everything in RAM. When memory runs out, it starts evicting keys based on your maxmemory-policy. The default is noeviction, which means writes will fail. That’s a hard crash for your app.
Monitor these metrics from INFO:
used_memory– Current RAM usage.used_memory_peak– The highest it’s ever been.maxmemory– Your configured limit.evicted_keys– Number of keys removed due to memory pressure.
A simple Python check:
if info['evicted_keys'] > 0:
print("Warning: Keys are being evicted. Check memory usage.")
If you see evictions, you have two choices: increase maxmemory or change your eviction policy. For most apps, allkeys-lru is a safe bet. It removes the least recently used keys when memory runs low.
Latency: The Hidden Problem
Redis is supposed to be fast. If a command takes 50 milliseconds, something is wrong. But you won’t notice it until users complain.
Redis has a built-in latency monitor. Enable it with:
CONFIG SET latency-monitor-threshold 100
This logs any command that takes longer than 100 milliseconds. Then check it with:
LATENCY LATEST
In Python, you can also measure latency yourself:
import time
start = time.time()
r.ping()
latency = time.time() - start
if latency > 0.1:
print(f"High latency detected: {latency:.3f} seconds")
If you see latency spikes, check your network. Redis is usually on the same machine or a very fast local network. If it’s across a data center, that’s your bottleneck.
The Slow Log: Your Best Debugging Tool
Redis has a built-in slow log. It records every command that takes longer than a threshold you set. By default, it’s 10 milliseconds. You can check it with SLOWLOG GET.
slow = r.slowlog_get(10)
for entry in slow:
print(f"Command: {entry['command']}, Duration: {entry['duration']} microseconds")
If you see a command taking 50 milliseconds or more, investigate. Common culprits:
KEYS *– Never use this in production. UseSCANinstead.SMEMBERSon a set with millions of items.SORTwith a large dataset.
The slow log is your first clue. If it’s empty, great. If it’s not, you have work to do.
Memory: The Silent Killer
Redis stores everything in RAM. When memory runs out, it starts evicting keys based on your maxmemory-policy. The default is noeviction, which means writes will fail. That’s a hard crash for your app.
Monitor these metrics from INFO:
used_memory– Current RAM usage.used_memory_peak– The highest it’s ever been.maxmemory– Your configured limit.evicted_keys– Number of keys removed due to memory pressure.
A simple Python check:
if info['evicted_keys'] > 0:
print("Warning: Keys are being evicted. Check memory usage.")
If you see evictions, you have two choices: increase maxmemory or change your eviction policy. For most apps, allkeys-lru is a safe bet. It removes the least recently used keys when memory runs low.
Latency: The Hidden Problem
Redis is supposed to be fast. If a command takes 50 milliseconds, something is wrong. But you won’t notice it until users complain.
Redis has a built-in latency monitor. Enable it with:
CONFIG SET latency-monitor-threshold 100
This logs any command that takes longer than 100 milliseconds. Then check it with:
LATENCY LATEST
In Python, you can also measure latency yourself:
import time
start = time.time()
r.ping()
latency = time.time() - start
if latency > 0.1:
print(f"High latency detected: {latency:.3f} seconds")
If you see latency spikes, check your network. Redis is usually on the same machine or a very fast local network. If it’s across a data center, that’s your bottleneck.
The Slow Log: Your Best Debugging Tool
Redis has a built-in slow log. It records every command that takes longer than a threshold you set. By default, it’s 10 milliseconds. You can check it with SLOWLOG GET.
slow = r.slowlog_get(10)
for entry in slow:
print(f"Command: {entry['command']}, Duration: {entry['duration']} microseconds")
If you see a command taking 50 milliseconds or more, investigate. Common culprits:
KEYS *– Never use this in production. UseSCANinstead.SMEMBERSon a set with millions of items.SORTwith a large dataset.
The slow log is your first clue. If it’s empty, great. If it’s not, you have work to do.
Memory: The Silent Killer
Redis stores everything in RAM. When memory runs out, it starts evicting keys based on your maxmemory-policy. The default is noeviction, which means writes will fail. That’s a hard crash
Advertisement
Comments
Questions, corrections, and tips stay visible for everyone reading this page.
Join the discussion
No comments yet
Be the first to leave a note — it helps the next reader.