Oliver Salzburg
Oliver Salzburg

Reputation: 22099

How can I see which keys have been missed?

I'm seeing a lot of cache misses on our Redis instance and I'm assuming this is due to a programming error where keys are looked up which were never stored.

I can run MONITOR to see all commands live, but that is impossible to follow and also doesn't seem to indicate if a key was hit or missed.

Does Redis itself provide any means to see which keys have been missed?

Upvotes: 2

Views: 4528

Answers (2)

osterik
osterik

Reputation: 76

It's become possible starting with Redis 6.0. New key 'm' added:

m Key miss events (events generated when a key that doesn't exist is accessed)

For example, you can see missed keys in console with 'redis-cli':

user@redis-server:~# redis-cli config set notify-keyspace-events Km
OK
user@redis-server:~# redis-cli --csv psubscribe '__key*__:*'
Reading messages... (press Ctrl-C to quit)
"psubscribe","__key*__:*",1
"pmessage","__key*__:*","__keyevent@0__:keymiss","<< actual data >>"
......

source: https://redis.io/topics/notifications

Upvotes: 3

Carl Zulauf
Carl Zulauf

Reputation: 39558

The Redis info command contains keyspace_hits and keyspace_misses in its various statistics. keyspace_misses will increment every time you ask to read from a key Redis doesn't have.

If you need more granular information I suggest modifying your cache fetch logic to write missing keys to a Redis sorted set or list so you can see which keys are going missing. You'll have to also come up with a way of purging this data periodically so it doesn't grow out of control, unless your total keyspace is pretty limited.

Upvotes: 4

Related Questions