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
command just shows me the total size and the number of keys per database which doesn't give me much insight... So any tools/ideas that give me more information when monitoring the redis server would be appreciated.
The Redis documentation doesn't show me any commands that can return the consumed memory of certain keys, so I guess if any buggy code would write a lot of "trash" to redis this could be really hard to find...
To get the size of a database in Redis, use the DBSIZE command. This returns the total number of keys stored in the currently selected database. The previous command returns the number of keys in the database at index 0. Another command you can use to get the database size is the info command.
To get the value stored in a key, you can use the GET command followed by the name of the key. The above command tells Redis to fetch the value stored in the specified key. We can use the GET command followed by the unique value as: GET username:3.
The maximum allowed key size is 512 MB.
To get the size of a database in Redis, use the DBSIZE command. This returns the total number of keys stored in the currently selected database. The previous command returns the number of keys in the database at index 0. Another command you can use to get the database size is the info command.
Redis DBSIZE command is used to get the number of keys in selected database. Integer reply. Following is the basic syntax of Redis DBSIZE command.
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) Show activity on this post.
You can use the following command to list the databases for which some keys are defined: INFO keyspace # Keyspace db0:keys=6002,expires=0,avg_ttl=0 db9:keys=20953296,expires=0,avg_ttl=0 db10:keys=1,expires=0,avg_ttl=0 You can also use Select 0 or Select 1 or any db which you want to check with the current size.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With