For debugging some issues, it would be helpful if there was a "redis monitor" that is command & key only or command + key + truncated value (e.g. first 10 characters of value and trunc) only.
As some users store huge amounts of data in 1 value, using monitor in cli is super unhelpful as the values are multiple pages, so I cannot get any useful data from redis directly (always have to write to file & then remove all values, but that is not showing me whats going on in redis in realtime)
Comment From: itamarhaber
Hello @kkmuffme
You can get this behavior by turning on the Redis Keyspace Notifications and then using PSUBSCRIBE with the cli (or any other client).
Comment From: kkmuffme
Thanks, but afaik this is slightly different. From the link you provided:
IMPORTANT all the commands generate events only if the target key is really modified. For instance an SREM deleting a non-existing element from a Set will not actually change the value of the key, so no event will be generated.
This means that if someone runs a DEL on a non-existing key, I will see this in monitor, but I won't see this with keyspace notifications?
===
Just so I understand how this would work, is this correct to get command + key (without value) only?
redis-cli config set notify-keyspace-events KEA
redis-cli psubscribe '__key*__:*'
# disable again
redis-cli config set notify-keyspace-events ""
Comment From: itamarhaber
This means that if someone runs a DEL on a non-existing key, I will see this in monitor, but I won't see this with keyspace notifications?
Yes, that is correct. I agree that notifications are not a perfect replacement for the proposed "debug monitor", but otoh they are available now ;)
Just so I understand how this would work, is this correct to get command + key (without value) only?
Basically yes, but use a simpler pattern:
redis-cli psubscribe '__key*'
Comment From: kkmuffme
Thanks, still for debugging it's not super useful if quite a bit of data is missing.
So perhaps the suggestion is to include an option to always generate an event, even when no key is changed?
Comment From: WiFeng
redis-cli monitor | grep "xxx", is it ok ? You can use all linux commands, eg. grep, awk and sed.
Comment From: kkmuffme
@WiFeng and how would I go on about truncating it at the e.g. 10th character of the key's value? Since the key length is variable & there is no specific pattern for the key, I am not sure how this is possible
Comment From: WiFeng
redis-cli monitor | awk -F\" '{printf("%s", $1); for (i=2; i<NF; i++) if ($i != " ") { printf("\"%s\" ", substr($i, 0, 10));} print " " }'
before:
OK
1589530954.974109 [0 127.0.0.1:60224] "set" "a" "vvvvvvvvv vvvvvvvvvvvvvvvv"
1589530955.796118 [0 127.0.0.1:60224] "set" "a" "vvvvvvvvv vvvvvvvvvvvvvvvv"
1589530956.476464 [0 127.0.0.1:60224] "set" "a" "vvvvvvvvv vvvvvvvvvvvvvvvv"
1589530957.116632 [0 127.0.0.1:60224] "set" "a" "vvvvvvvvv vvvvvvvvvvvvvvvv"
1589530957.740792 [0 127.0.0.1:60224] "set" "a" "vvvvvvvvv vvvvvvvvvvvvvvvv"
1589530958.860438 [0 127.0.0.1:60224] "set" "a" "vvvvvvvvv vvvvvvvvvvvvvvvv"
1589530959.485424 [0 127.0.0.1:60224] "set" "a" "vvvvvvvvv vvvvvvvvvvvvvvvv"
after:
OK
1589530888.860323 [0 127.0.0.1:60224] "set" "a" "vvvvvvvvv "
1589530895.588792 [0 127.0.0.1:60224] "set" "a" "vvvvvvvvv "
1589530896.596287 [0 127.0.0.1:60224] "set" "a" "vvvvvvvvv "
1589530897.387677 [0 127.0.0.1:60224] "set" "a" "vvvvvvvvv "
1589530898.219940 [0 127.0.0.1:60224] "set" "a" "vvvvvvvvv "
1589530899.252217 [0 127.0.0.1:60224] "set" "a" "vvvvvvvvv "
1589530900.539969 [0 127.0.0.1:60224] "set" "a" "vvvvvvvvv "
This shell command truncates all fields.
Comment From: kkmuffme
@WiFeng Thanks :+1: