Friday, February 20, 2015

How To Find Out Size Of A Key In Redis

Redis can do special encoding for some data types to save space while storing data in memory. So if you want to know the actual memory space occupied by a key value in redis server, use the following command:

DEBUG OBJECT <KEY>

For example, look at the following command and output:

redis localhost:6379> DEBUG OBJECT sample_key
Value at:0x7f36f2980900 refcount:1 encoding:raw serializedlength:4 
lru:582042 lru_seconds_idle:1423688

Here serializedlength is 4. That means the value is taking up 4 bytes of memory in redis server after it gets serialized and stored. This command can be pretty useful if you want to check some particular type of keys take up how much memory generally when their data gets stored in redis.
 

 

No comments:

Post a Comment