database configuration_error ai_generated true

OOM command not allowed when used memory > 'maxmemory'

ID: database/redis-maxmemory-policy

Also available as: JSON · Markdown
90%Fix Rate
92%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
7 active

Root Cause

Redis has reached its maxmemory limit and the configured eviction policy (maxmemory-policy) does not allow eviction, or all keys have been checked and none are eligible for eviction. The default policy is 'noeviction', which returns OOM errors for write commands when memory is full. This is distinct from the OS-level OOM killer and is entirely a Redis-level memory management decision.

generic

Workarounds

  1. 92% success Configure an appropriate eviction policy based on your use case
    For cache-only Redis: CONFIG SET maxmemory-policy allkeys-lru (evicts least recently used keys). For mixed cache and persistent data: CONFIG SET maxmemory-policy volatile-lru (only evicts keys with a TTL set). For time-series data: CONFIG SET maxmemory-policy volatile-ttl (evicts keys closest to expiry). Make persistent in redis.conf: maxmemory-policy allkeys-lru. Always ensure important persistent keys do not have a TTL when using volatile-* policies.
  2. 88% success Reduce memory usage by optimizing data structures and setting TTLs
    Set TTL on all cache keys: SET key value EX 3600. Use Redis memory-efficient data structures: use hashes for small objects (hash-max-ziplist-entries 128). Audit large keys: redis-cli --bigkeys. Check memory usage: INFO memory, MEMORY USAGE key. Consider using Redis data structure optimizations: ziplist, intset, listpack. Move large values to external storage (S3/disk) and store only references in Redis.

Dead Ends

Common approaches that don't work:

  1. Setting maxmemory to 0 (unlimited) on a machine with limited RAM 85% fail

    With maxmemory=0, Redis uses all available system memory until the Linux OOM killer terminates it, causing a hard crash with potential data loss. The RDB/AOF save may not complete, and the process dies without cleanup. This is worse than the OOM error because it is an uncontrolled crash rather than a controlled rejection.

  2. Using allkeys-random eviction policy to avoid OOM errors 65% fail

    allkeys-random evicts keys randomly regardless of importance, access pattern, or TTL. Critical keys (session tokens, rate limiters, feature flags) may be evicted while stale, unused keys are kept. This causes unpredictable application behavior that is difficult to debug.

Error Chain

Leads to:
Preceded by:
Frequently confused with: