Reputation: 61
I'm interested to log which users connected to the database and when.
MONITOR command is overkill and cause dramatic decrease in throughput.
What is the recommended method to publish/generate these logs?
There are probably no available commands in redis for auditing except MONITOR
redis-cli monitor
Using MONITOR command I will get something like this:
1339518083.107412 [0 127.0.0.1:60866] "keys" "*"
1339518087.877697 [0 127.0.0.1:60866] "dbsize"
1339518090.420270 [0 127.0.0.1:60866] "set" "x" "6"
1339518096.506257 [0 127.0.0.1:60866] "get" "x"
1339518099.363765 [0 127.0.0.1:60866] "del" "x"
1339518100.544926 [0 127.0.0.1:60866] "get" "x"
while I need something more like: user X connected at timestamp Y
Upvotes: 0
Views: 4002
Reputation: 612
You can use CLIENT LIST command to get this info. Make sure to set the client name when client creates connection to Redis. Then look at the 'age' field printed by CLIENT LIST to get total duration of the connection in seconds.
redis 127.0.0.1:6379> client list
addr=127.0.0.1:52555 fd=5 name=ClientName1 age=855 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=client
addr=127.0.0.1:52787 fd=6 name=ClientName2 age=6 idle=5 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=ping
https://redis.io/commands/client-list
Upvotes: 1