Reputation: 61
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
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:
MONITOR
, parse the output and make your own statistics. Beware, however, of the command's impact on performance in production environments.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