Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis: Show database size/size for keys

Tags:

redis

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...

like image 526
Bernhard Vallant Avatar asked Oct 03 '11 17:10

Bernhard Vallant


People also ask

How do I find the size of my Redis database?

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.

How do I find my Redis key-value?

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.

What is the recommended size for Redis keys?

The maximum allowed key size is 512 MB.

How do I get the size of a database in Redis?

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.

How to get the number of keys in selected database using Redis?

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.

What is the use of memory usage in Redis?

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.

How to check the current key size for a specific database?

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.


1 Answers

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.

like image 50
Bernhard Vallant Avatar answered Oct 12 '22 14:10

Bernhard Vallant