How to fix OOM Out of memory in Redis

RedisINTERMEDIATEHIGHUpdated Dec 29, 2025ยท 192 views

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
  1. Check current memory usage
  2. Quick fix - flush non-essential data
  3. Configure an appropriate eviction policy
  4. Set expiration times (TTL) on keys
redis โ€” error
redis-cli info memory
OOM 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

  1. Maxmemory limit is set too low for your data volume
  2. Eviction policy is "noeviction" which prevents automatic key removal when limit is reached
  3. Volatile eviction policies (volatile-lru, volatile-ttl) have no keys with TTL to evict
  4. Data growth rate exceeds the eviction rate in high-write scenarios
  5. Keys are accumulating without expiration times being set
  6. Memory fragmentation prevents Redis from reusing available space

How to fix "OOM Out of memory"

1Check current memory usage

Connect to Redis and view memory statistics to understand how much memory is being used:

bash
redis-cli info memory

Look for used_memory_human and compare it to maxmemory. If used_memory is near or exceeding maxmemory, that confirms the OOM condition.

2Quick fix - flush non-essential data

If this is a development or test environment, you can clear the cache:

bash
redis-cli flushall

For production, selectively delete old or unnecessary keys:

bash
redis-cli --bigkeys  # Find the largest keys
redis-cli DEL key_name  # Remove specific keys
3Configure an appropriate eviction policy

Change from noeviction to an eviction policy that automatically removes keys when the limit is reached:

bash
redis-cli CONFIG SET maxmemory-policy allkeys-lru

Common 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:

bash
maxmemory-policy allkeys-lru
4Set expiration times (TTL) on keys

When using volatile policies, ensure keys have expiration times:

bash
redis-cli SET mykey "value" EX 3600  # Expires in 1 hour
redis-cli EXPIRE existingkey 3600

In your application code:

python
# Python example
redis_client.setex("cache_key", 3600, "value")  # 1 hour TTL

# Node.js example
await redis.setex("cache_key", 3600, "value");  # 1 hour TTL
5Increase maxmemory limit

If your legitimate data exceeds the current limit:

bash
redis-cli CONFIG SET maxmemory 512mb

For permanent changes, edit redis.conf:

bash
maxmemory 512mb

Then 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.

6Enable monitoring and alerting

Monitor memory usage continuously to catch issues before they cause OOM:

bash
redis-cli --stat  # Real-time memory stats

Set 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