How to fix OOM Out of memory in Redis
Redis has reached its maxmemory limit and cannot store new data. This occurs when memory usage exceeds the configured limit and the eviction policy cannot free enough space for new operations.
Quick fix
Fixes OOM Out of memory
redis-cli info memory- Check current memory usage
- Quick fix - flush non-essential data
- Configure an appropriate eviction policy
- Set expiration times (TTL) on keys
redis-cli info memoryOOM Out of memory
What this error means
The "OOM Out of memory" error indicates that your Redis instance has exhausted its allocated memory. Redis is an in-memory data store, and when the amount of data stored reaches the maxmemory limit you have configured, Redis cannot accept new write operations. This is a safety mechanism to prevent the server from consuming unlimited system memory. The error typically appears when executing commands that would add new data to the database, though read operations continue to work normally.
Typical symptoms
- Write operations fail with "OOM command not allowed when used memory > maxmemory"
- SET, LPUSH, HSET, and other data modification commands return OOM errors
- Read operations (GET, HGET, LRANGE) continue to work
- New cache entries cannot be stored
- Application experiences sudden data storage failures
- Cache misses increase dramatically as new data is rejected
Common causes
- Maxmemory limit is set too low for your data volume
- Eviction policy is "noeviction" which prevents automatic key removal when limit is reached
- Volatile eviction policies (volatile-lru, volatile-ttl) have no keys with TTL to evict
- Data growth rate exceeds the eviction rate in high-write scenarios
- Keys are accumulating without expiration times being set
- Memory fragmentation prevents Redis from reusing available space
How to fix "OOM Out of memory"
Connect to Redis and view memory statistics to understand how much memory is being used:
redis-cli info memoryLook for used_memory_human and compare it to maxmemory. If used_memory is near or exceeding maxmemory, that confirms the OOM condition.
If this is a development or test environment, you can clear the cache:
redis-cli flushallFor production, selectively delete old or unnecessary keys:
redis-cli --bigkeys # Find the largest keys
redis-cli DEL key_name # Remove specific keysChange from noeviction to an eviction policy that automatically removes keys when the limit is reached:
redis-cli CONFIG SET maxmemory-policy allkeys-lruCommon policies:
- allkeys-lru: Evict least recently used keys (recommended for most caches)
- volatile-lru: Evict least recently used keys with expiration only
- allkeys-lfu: Evict least frequently used keys
- volatile-ttl: Evict keys with shortest TTL first
To persist this change, update your redis.conf:
maxmemory-policy allkeys-lruWhen using volatile policies, ensure keys have expiration times:
redis-cli SET mykey "value" EX 3600 # Expires in 1 hour
redis-cli EXPIRE existingkey 3600In your application code:
# Python example
redis_client.setex("cache_key", 3600, "value") # 1 hour TTL
# Node.js example
await redis.setex("cache_key", 3600, "value"); # 1 hour TTLIf your legitimate data exceeds the current limit:
redis-cli CONFIG SET maxmemory 512mbFor permanent changes, edit redis.conf:
maxmemory 512mbThen restart Redis for the configuration to take effect. For managed Redis services (AWS ElastiCache, Google Cloud Memorystore, Azure Cache), scale up the node type through the service console.
Monitor memory usage continuously to catch issues before they cause OOM:
redis-cli --stat # Real-time memory statsSet up alerts when memory usage approaches the maxmemory limit (e.g., at 80% capacity). Most Redis managed services have built-in monitoring. For self-hosted Redis, use tools like Prometheus + Grafana or DataDog to track used_memory over time.
Advanced notes
Memory fragmentation can cause issues where Redis reports high memory usage but cannot evict keys effectively. Use redis-cli INFO memory to check the mem_fragmentation_ratio (values above 1.5 indicate fragmentation). You can reduce fragmentation by restarting Redis or using the MEMORY PURGE command. For replicas, eviction policies only apply to the primary instance unless the replica is promoted. High write-rate workloads may accumulate data faster than the eviction background process can remove keys, so monitor write patterns and consider scaling horizontally with sharding if a single instance cannot keep up.
Frequently asked questions
- What does "OOM Out of memory" mean?
- The "OOM Out of memory" error indicates that your Redis instance has exhausted its allocated memory. Redis is an in-memory data store, and when the amount of data stored reaches the maxmemory limit you have configured, Redis cannot accept new write operations. This is a safety mechanism to prevent the server from consuming unlimited system memory.
- How do I fix "OOM Out of memory"?
- Redis has reached its maxmemory limit and cannot store new data. This occurs when memory usage exceeds the configured limit and the eviction policy cannot free enough space for new operations.
- What causes "OOM Out of memory"?
- Maxmemory limit is set too low for your data volume Eviction policy is "noeviction" which prevents automatic key removal when limit is reached Volatile eviction policies (volatile-lru, volatile-ttl) have no keys with TTL to evict
- Is the "OOM Out of memory" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.
Official resources & further reading
- ๐Redis Official Documentation
- ๐Redis Docs - Error Handling(Official Docs)
- ๐Redis Docs - Eviction Policy(Official Docs)
- ๐Redis Docs - Key Eviction(Official Docs)
- ๐Google Cloud - Memory Management Best Practices(Official Docs)
- ๐AWS - OOM Error Resolution(Official Docs)