I have a Python script that executes Redis commands via redis-py. How can I print the commands being executed when the script runs for debugging purposes? I have access to both the code and the Redis server.
1 Answer
You can use the Monitor command.
All you have to do is open the redis-cli and call MONITOR, and then it will log every command sent to Redis.
$ redis-cli
127.0.0.1:6379> MONITOR
OK
1617778908.016538 [0 127.0.0.1:38138] "set" "foo" "bar"
1 Comment
Mark Setchell
Great solution! Might be worth adding that you don't actually need to "enter" the CLI, you can start monitoring from outside if you want to redirect the output to a file or process it with
awk or similar, e.g. redis-cli MONITOR | awk '...' or like redis-cli MONITOR > redis.log
loggingpymotw.com/3/logging/index.html to the Redis calls.