1

In my application I am implementing a server-side cache using Redis (for mySQL database). When data change in the database, I want to completely clear the cache to invalidate the old data.

However, I would like to see some statistics about how often are different keys queried in Redis, so that I can sort of manually pre-fetch frequently queried data for them to be available immediately after clearing the cache.

Is there any way how to see these statistics directly in Redis? Or what is a common solution to this problem?

P. Paul
  • 363
  • 3
  • 17

2 Answers2

1

You can use the object command.

OBJECT FREQ returns the logarithmic access frequency counter of the object stored at the specified key. This subcommand is available when maxmemory-policy is set to an LFU policy.

https://redis.io/commands/object

LeoMurillo
  • 6,048
  • 1
  • 19
  • 34
  • Thank you, this is just what I needed. Also, do you know how I could iterate over all keys to call OBJECT FREQ on them? I know that `SCAN` exists, but I cant find how to call `OBJECT FREQ` for each key within the `SCAN`. – P. Paul Jan 22 '20 at 15:27
  • You would use SCAN and the call the command, you can implement a Lua script to this more efficiently. [This answer](https://stackoverflow.com/questions/7462457/how-can-i-get-all-of-the-sets-in-redis/59564727#59564727) can get you started. – LeoMurillo Jan 22 '20 at 15:31
1

redis-cli --hotkeys can do the help for redis-cli version 4.x and above.

Fify
  • 131
  • 1
  • 8