Skip to content

Error explained

Redis: OOM command not allowed when used memory > maxmemory

Redis reached maxmemory and its eviction policy does not allow removing keys, so writes are refused. Either let it evict, give keys a TTL, or give it more memory.

3 min read9 sectionsUpdated

On this page

Key points

  • noeviction (the default) refuses writes at the limit.
  • Caches should use allkeys-lru or allkeys-lfu.
  • Keys without TTLs accumulate forever.
  • Big keys can use far more memory than expected.

Check memory and policy

bash
redis-cli INFO memory | grep -E 'used_memory_human|maxmemory_human|maxmemory_policy|mem_fragmentation_ratio'
redis-cli INFO keyspace                 # keys and keys with expiry per db
redis-cli --bigkeys                     # largest keys per type (scans; run off-peak)
redis-cli MEMORY USAGE some:key

Choose the right eviction policy

Use of RedisPolicy
Pure cacheallkeys-lru or allkeys-lfu
Cache with some permanent keysvolatile-lru (only keys with a TTL are evicted)
Primary data store, queues, locksnoeviction, plus alerts well before the limit

Fixes

  • Set TTLs on cache entries and session keys.
  • Remove or split big keys (huge hashes, lists used as unbounded logs).
  • Use a dedicated Redis for queues and another for cache, with different policies.
  • If fragmentation is high, enable activedefrag or restart during a quiet time.
  • Add memory only after the above; data that only grows will hit any limit.

Catching it in production

Alert on used memory above 85 to 90% of maxmemory and on evicted_keys for instances that should not evict. Application errors from refused writes appear in traces as failed Redis client spans.

VitalRix error tracking groups exceptions recorded on OpenTelemetry spans into issues with counts, first and last seen, affected endpoints and versions, and marks an issue as regressed if it comes back after being resolved. Alert rules on error rate per service or endpoint route the problem to the right team before customers report it.

A worked example

A session store runs Redis with maxmemory 2gb and the default noeviction. A release stops setting a TTL on session keys. Memory climbs for two weeks until writes fail with OOM and users cannot sign in. INFO keyspace shows 3.1 million keys with only 40,000 having an expiry. The fix: restore the TTL in code, run a one-off script with SCAN to set expiries on existing session keys, and add an alert on memory above 85% of maxmemory so the next slow climb is caught early.

Frequently asked questions

Why is used memory higher than my data?

Per-key overhead, data structure encoding and fragmentation all add up. MEMORY USAGE and INFO memory show the details.

Will eviction lose important data?

With allkeys policies, any key can be evicted. Keep data you cannot lose in a separate instance with noeviction.

Watch your own site and services with VitalRix

Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.