appanponn
appanponn

Reputation: 465

Memory utilization in redis for each database

Redis allows storing data in 16 different 'databases' (0 to 15). Is there a way to get utilized memory & disk space per database. INFO command only lists number of keys per database.

Upvotes: 11

Views: 6235

Answers (2)

Mathieu Longtin
Mathieu Longtin

Reputation: 16700

I did it by calling dump on all the keys in a Redis DB and measuring the total number of bytes used. This will slow down your server and take a while. It seems the size dump returns is about 4 times smaller than the actual memory use. These number will give you an idea of which db is using the most space.

Here's my code: https://gist.github.com/mathieulongtin/fa2efceb7b546cbb6626ee899e2cfa0b

Upvotes: 0

Ofer Zelig
Ofer Zelig

Reputation: 17480

No, you can not control each database individually. These "databases" are just for logical partitioning of your data.

What you can do (depends on your specific requirements and setup) is spin multiple redis instances, each one does a different task and each one has its own redis.conf file with a memory cap. Disk space can't be capped though, at least not in Redis level.

Side note: Bear in mind that the 16 database number is not hardcoded - you can set it in redis.conf.

Upvotes: 5

Related Questions