My redis instance seems to being growing very large and I\'d like to find out which of the multiple databases I have in there consumes how much memory. Redis\' INFO
You might find it very useful to sample Redis keys and group them by type. Salvatore has written a tool called redis-sampler that issues about 10000 RANDOMKEY
commands followed by a TYPE
on retrieved keys. In a matter of seconds, or minutes, you should get a fairly accurate view of the distribution of key types.
I've written an extension (unfortunately not anywhere open-source because it's work related), that adds a bit of introspection of key names via regexs that give you an idea of what kinds of application keys (according to whatever naming structure you're using), are stored in Redis. Combined with the more general output of redis-sampler, this should give you an extremely good idea of what's going on.
Perhaps you can do some introspection on the db file. The protocol is relatively simple (yet not well documented), so you could write a parser for it to determine which individual keys are taking up a lot of space.
New suggestions:
Have you tried using MONITOR
to see what is being written, live? Perhaps you can find the issue with the data in motion.
You can use .net application https://github.com/abhiyx/RedisSizeCalculator to calculate the size of redis key,
Please feel free to give your feedback for the same
I usually prefer the key sampling method to troubleshoot such scenarios.
redis-cli -p 6379 -n db_number --bigkeys
Eg:-
redis-cli -p 6370 -n 0 --bigkeys
How about redis-cli get KEYNAME | wc -c
Take a look at this project it outputs some interesting stats about keyspaces based on regexs and prefixes. It uses the DEBUG OBJECT
command and scans the db, identifying groups of keys and estimating the percentage of space they're taking up.
https://github.com/snmaynard/redis-audit
Output looks like this:
Summary
---------------------------------------------------+--------------+-------------------+---------------------------------------------------
Key | Memory Usage | Expiry Proportion | Last Access Time
---------------------------------------------------+--------------+-------------------+---------------------------------------------------
notification_3109439 | 88.14% | 0.0% | 2 minutes
user_profile_3897016 | 11.86% | 99.98% | 20 seconds
---------------------------------------------------+--------------+-------------------+---------------------------------------------------
Or this this one: https://github.com/sripathikrishnan/redis-rdb-tools which does a full analysis on the entire keyspace by analyzing a dump.rdb file offline. This one works well also. It can give you the avg/min/max size for the entries in your db, and will even do it based on a prefix.