Redis is known for its super-fast performance and utility as an in-memory data store. Sometimes, I would want to peek under the hood to monitor what commands our Redis instance is receiving; especially if when debugging an application or analyzing performance.
In this post, I will detail the tools and commands I use and find useful.
My Go-To: Using the MONITOR
Command
Whenever I need to get a live feed of every command processed by my Redis server, the first tool I use is the MONITOR
command. It’s my real-time debugging sidekick, and it shows me everything happening on the server.
How to Use It:
- First, connect to the Redis instance using the CLI:
redis-cli
- Then, run the
MONITOR
command:
MONITOR
- Instantly, see the output like this:
1669234856.223456 [0 127.0.0.1:6379] "GET" "key"
1669234856.123456 [0 127.0.0.1:6379] "SET" "key" "value"
Why I find it useful:
- I get a real-time feed of every command hitting the Redis instance.
- It’s perfect for debugging my application or understanding what’s happening under the hood.
Note:
- The
MONITOR
command can produce a LOT of data, especially on busy servers. - I use it rarely in production environments and prefer to run it on a replica to avoid performance hits.
Logging Commands to a File
There have been times when I needed a trail record of commands, and that’s when I turned to Redis logging. We can capture commands without constantly monitoring them in real time by setting the Redis configuration for logging.
Here’s how:
- Edit the Redis configuration file (
redis.conf
) to enable verbose logging:
logfile /var/log/redis/redis.log
loglevel verbose
- After saving the changes, restart Redis to apply them:
sudo systemctl restart redis
- Use the
tail
command to monitor the log file:
tail -f /var/log/redis/redis.log
Why I Like It:
- It’s great for analyzing past activity or troubleshooting over time.
- The logs are always there when I need them.
The Trade-Off:
- Logging at
verbose
level generates huge files, so I’ve had to keep an eye on disk space and set up log rotation. - It’s not as immediate as the
MONITOR
command, but it’s more persistent.
Using Keyspace Notifications
When I needed to track specific events, like when keys were updated or expired, Redis Keyspace Notifications are useful. It’s not a full command monitor, but it’s perfect for targeted use cases.
How to do it:
- Enable notifications dynamically:
redis-cli CONFIG SET notify-keyspace-events KEA
Here:
K
: Keyspace events.E
: Key event notifications.A
: All events.
- Then, subscribe to the notifications using
PSUBSCRIBE
:
redis-cli
PSUBSCRIBE "__key*__:*"
- The output will look something like this:
pmessage __keyspace@0__:mykey "set"
pmessage __keyevent@0__:mykey "expire"
Why It’s Useful:
- It’s great for tracking specific key events, like expirations or updates.
- I use it to debug TTL-related issues or monitor key-specific operations.
What It Doesn’t Do:
- It’s not a replacement for
MONITOR
or logging—it’s more focused on key-level events.
My Experience with GUI Tools
I have relied on some third-party and GUI tools when I needed a more visual way to monitor Redis. My personal favorite has been RedisInsight. It’s a GUI tool that makes it easy to track activity, analyze performance, and debug commands.
Wrapping Up
These are some of the tools I’ve used for my use cases.
- For real-time debugging, use the
MONITOR
. - For persistent tracking, configure logging.
- When you need key-specific insights, Keyspace Notifications are a great choice.
- And for a polished, visual experience, RedisInsight is hard to beat.
And hey, if you’ve got your own Redis monitoring tips, I’d love to hear about them in the comments!