shanky123
shanky123

Reputation: 61

How to get Redis key hit count?

Is there way to get all the keys stored in a database with their hit counts?

I want to sort the keys by their hit counts.

Upvotes: 3

Views: 4712

Answers (1)

Itamar Haber
Itamar Haber

Reputation: 49942

As of v4.0.1, Redis doesn't offer this capability. If you need it in order to free up space by removing unused keys, you should perhaps consider using Redis' expiry mechanisms for that.

There are a couple of approaches you can try to get close to what you want:

  • Run MONITOR, parse the output and make your own statistics. Beware, however, of the command's impact on performance in production environments.
  • Activate an LFU eviction policy (new in v4, can be set to volatile-lfu if you don't use expiry), and then SCAN following by calling OBJECT freq on each key.

That said, there is a current effort in the pipes (https://github.com/antirez/redis/issues/4473) to improve the detection of hot keys when using LFU.

UPDATE: redis-cli has been added with the --hotkeys mode that operates as described in the 2nd bullet.

Upvotes: 4

Related Questions