Redis does not seem to provide a reliable method to obtain the actual occupation of each db. This is mainly because redis itself does not have the concept of db files, and all dbs are mixed in one rdb file.
To estimate the size of db, you need to pass keys * 遍历 db 里所有的 key,然后用 debug object <key> 来获得 key 的内存占用,serializedlength which is the length of the field occupying memory.
According to the RDB format document, it can be estimated that the actual occupation of each key is:
key_size = strlen(key) + serializedlength + 7
However, this estimate is extremely unreliable, because redis may compress the key, and the estimated value may be too large.
The following command can check the size of db0 (number of keys), and so on for others.
select 0
dbsize
Or use info keyspace to get all db information at the same time.
Redis does not seem to provide a reliable method to obtain the actual occupation of each db. This is mainly because redis itself does not have the concept of db files, and all dbs are mixed in one rdb file.
To estimate the size of db, you need to pass
keys *
遍历 db 里所有的 key,然后用debug object <key>
来获得 key 的内存占用,serializedlength
which is the length of the field occupying memory.According to the RDB format document, it can be estimated that the actual occupation of each key is:
However, this estimate is extremely unreliable, because redis may compress the key, and the estimated value may be too large.
The following command can check the size of
db0
(number of keys), and so on for others.Or use
info keyspace
to get all db information at the same time.