David - Musings of an SRE

Debugging Redis and its Memory

To determine the size of a key

redis-cli> DEBUG OBJECT <keyname>

Value at:0x7ffc8f8eb330 refcount:1 encoding:linkedlist serializedlength:1175841791 lru:416416 lru_seconds_idle:30

serializedlength is in bytes.

To print out the size of each key in your redis-database

Checkout this script

To tweak Redis from overloading your memory

Add vm.overcommit_memory = 1 to /etc/sysctl.conf and then reboot or run the command sysctl vm.overcommit_memory=1 for this to take effect immediately.

To limit the size of your redis database

# /etc/redis/redis.conf
# add this
maxmemory <size> # can be in 1gb 1m 1kb
maxmemory-policy <policy> # details in comments of redis.conf