How to Use MONITOR Command in Redis: Syntax and Examples
Use the
MONITOR command in Redis to see all commands processed by the server in real time. Simply connect to Redis and run MONITOR; it will stream every command executed until you disconnect.Syntax
The MONITOR command has a simple syntax with no arguments. When you run it, Redis starts streaming all commands it receives.
MONITOR: Starts the monitoring session.
Once active, it shows every command executed by any client until you stop it by disconnecting.
redis
MONITOR
Example
This example shows how to use MONITOR in a Redis CLI session. It demonstrates monitoring commands executed by other clients.
redis
redis-cli > MONITOR OK # In another terminal: redis-cli SET key1 value1 redis-cli GET key1 # Output in MONITOR terminal: 1597681234.123456 [0 127.0.0.1:6379] "SET" "key1" "value1" 1597681235.123789 [0 127.0.0.1:6379] "GET" "key1"
Output
1597681234.123456 [0 127.0.0.1:6379] "SET" "key1" "value1"
1597681235.123789 [0 127.0.0.1:6379] "GET" "key1"
Common Pitfalls
1. High Performance Impact: Running MONITOR on a busy server can slow it down because it logs every command.
2. No Filtering: MONITOR shows all commands from all clients; it cannot filter by client or command type.
3. Use Only for Debugging: Avoid using MONITOR in production environments for long periods.
redis
# Wrong way: redis-cli MONITOR # Leave it running on a busy production server for hours # Right way: # Use MONITOR briefly for debugging, then disconnect redis-cli MONITOR # Observe commands # Press Ctrl+C to stop
Quick Reference
| Command | Description |
|---|---|
| MONITOR | Start streaming all commands processed by Redis |
| Ctrl+C (in CLI) | Stop monitoring and disconnect |
| No arguments | MONITOR does not accept any parameters |
| Use briefly | Avoid long monitoring sessions to prevent performance issues |
Key Takeaways
The MONITOR command streams all commands Redis processes in real time.
Use MONITOR only for short debugging sessions to avoid slowing down the server.
MONITOR shows commands from all clients without filtering options.
Stop monitoring by disconnecting or pressing Ctrl+C in the CLI.
MONITOR has no arguments and starts immediately when run.