11

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.

appanponn
  • 465
  • 4
  • 9

2 Answers2

5

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.

Ofer Zelig
  • 17,068
  • 9
  • 59
  • 93
  • This is another option, but I am not sure how much overhead in memory consumption for each instance. – appanponn Nov 04 '12 at 05:56
  • You can set maximum RAM all databases can utilize by using maxmemory in redis.conf file. This value is in BYTES. This is not per database but still, it should be set to avoid a scenario where redis utilizes all of RAM and OS have to kill it. Which will result in data loss or data having to be re-cached. – Saad Khan Nov 06 '21 at 20:40
0

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

Mathieu Longtin
  • 15,922
  • 6
  • 30
  • 40