database resource_error ai_generated true

redis.exceptions.ResponseError: -OOM command not allowed when used memory > 'maxmemory'.

ID: database/redis-maxmemory-policy-eviction-blocked

Also available as: JSON · Markdown · 中文
85%Fix Rate
90%Confidence
1Evidence
2023-11-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Redis 6.2 active
Redis 7.0 active
Redis 7.2 active

Root Cause

Redis has reached its maxmemory limit and the configured eviction policy (maxmemory-policy) cannot free enough space, or the policy is set to 'noeviction', causing write commands to be rejected.

generic

中文

Redis 已达到 maxmemory 限制,并且配置的逐出策略 (maxmemory-policy) 无法释放足够的空间,或者策略设置为 'noeviction',导致写命令被拒绝。

Official Documentation

https://redis.io/docs/latest/operate/oss_and_stack/management/admin/#maxmemory

Workarounds

  1. 90% success Set an appropriate eviction policy: CONFIG SET maxmemory-policy allkeys-lru (or volatile-lru, allkeys-lfu, etc.) via redis-cli. Then verify with CONFIG GET maxmemory-policy.
    Set an appropriate eviction policy: CONFIG SET maxmemory-policy allkeys-lru (or volatile-lru, allkeys-lfu, etc.) via redis-cli. Then verify with CONFIG GET maxmemory-policy.
  2. 80% success Increase maxmemory if feasible: CONFIG SET maxmemory 2gb (or edit redis.conf and restart). Also monitor memory usage with INFO memory to ensure the new limit is sufficient.
    Increase maxmemory if feasible: CONFIG SET maxmemory 2gb (or edit redis.conf and restart). Also monitor memory usage with INFO memory to ensure the new limit is sufficient.

中文步骤

  1. Set an appropriate eviction policy: CONFIG SET maxmemory-policy allkeys-lru (or volatile-lru, allkeys-lfu, etc.) via redis-cli. Then verify with CONFIG GET maxmemory-policy.
  2. Increase maxmemory if feasible: CONFIG SET maxmemory 2gb (or edit redis.conf and restart). Also monitor memory usage with INFO memory to ensure the new limit is sufficient.

Dead Ends

Common approaches that don't work:

  1. Increase maxmemory without addressing the eviction policy or data growth pattern 80% fail

    Memory will eventually fill up again if the root cause (e.g., unbounded cache growth, no eviction) is not fixed.

  2. Flush all keys using FLUSHALL or FLUSHDB without restarting or changing config 70% fail

    While this temporarily frees memory, the same pattern of writes will cause the error to recur unless the eviction policy is adjusted.