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
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
activedefragor 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.
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.
Related reading
- Redis latency spikes: how to diagnose and fix them: Diagnose Redis latency spikes: find slow commands with SLOWLOG, big keys, fork pauses from persistence, swapping and network delay, using built-in tools.
- Linux OOM killer: why it killed your process: Understand the Linux OOM killer: read the kernel log to see what was killed and why, how oom_score works, and how to protect critical services from it.
- How to find a Node.js memory leak: Detect a Node.js memory leak from heap metrics, compare heap snapshots to find what retains memory, fix the usual causes and alert before a crash.
- PHP "Allowed memory size exhausted": how to fix it: Fix PHP Fatal error: Allowed memory size exhausted. Read the error correctly, raise memory_limit for the right SAPI and stop loading big data into arrays.
- 405 Method Not Allowed: why it happens and how to fix it: Fix 405 Method Not Allowed: POST sent to a static file, redirects that turn POST into GET, CORS preflights and routing mismatches, with curl checks.
- Redis connection refused: how to fix it: Fix Redis connection refused on port 6379: server stopped, bind address, protected mode and Docker networking, with redis-cli and ss commands for each cause.
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.