A few days ago my Redis instance went down. All new write attempts failed with this error:
OOM command not allowed when used memory > 'maxmemory'
It only recovered after I flushed all the data. It runs in a VPS that has 24gb of RAM and only runs Redis, with this configuration:
maxmemory 20gb
maxmemory-policy volatile-lru
save ""
I use this instance to store sessions (notice though that persistence is disabled). Every session is written into Redis with an expiration time of 2 days, that means that all the keys have a TTL:
# Keyspace
db0:keys=1426936,expires=1425758,avg_ttl=87980766
Then why did it run out of memory? If the eviction policy is volatile-lru and all the keys have an expiration time set, why did it failed when it reached the maxmemory setting instead of evicting keys to free up memory?
Another thing to consider: the load of my application is very constant and stable, no peaks. The sessions are stored with an expiration time of 2 days. Now it's been six days running since I restarted the instance and flushed all, and Redis reports used_memory_human:781.54M. But when I check my server stats, I can see that the memory usage had been slowly increasing until the incident. And when I say slowly is really slowly: it took almost an year to reach the maxmemory=20gb limit.
But wait! How is that possible if sessions expire in two days? Could the incident be related to fragmentation ratio? I mean, sessions expire in two days, and all the time new sessions are being written to Redis. Is it possible that fragmentation ratio increased slowly during an year, making Redis fail regardless it had been configured with an eviction policy?
Or is there another theoretical situation where Redis can't free up memory fast enough? Thanks in advance!