Redis: Show database size/size for keys
MEMORY USAGE key
command gives you the number of bytes that a key and its value require to be stored in RAM.
The reported usage is the total of memory allocations for data and administrative overheads that a key its value require (source redis documentation)
The solution from the comments deserves its own answer:
redis-cli --bigkeys
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.
So my solution to my own problem: After playing around with redis-cli
a bit longer I found out that DEBUG OBJECT <key>
reveals something like the serializedlength
of key, which was in fact something I was looking for...
For a whole database you need to aggregate all values for KEYS *
which shouldn't be too difficult with a scripting language of your choice...
The bad thing is that redis.io doesn't really have a lot of information about DEBUG OBJECT
.