ERM redis resource_error ai_generated true

ERR Error running script (call to f_<sha>): @user_script: <line>: -OOM command not allowed when used memory > 'maxmemory'

ID: redis/lua-script-oom

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Redis 6.2.0 active
Redis 7.0.0 active
Redis 7.2.0 active

Root Cause

A Lua script attempted to execute a write command while the Redis instance exceeded its maxmemory limit, triggering the out-of-memory policy.

generic

中文

Lua 脚本尝试执行写命令,但 Redis 实例已超过 maxmemory 限制,触发了内存不足策略。

Official Documentation

https://redis.io/docs/latest/develop/interact/programmability/lua-api/

Workarounds

  1. 85% success Reduce script memory usage by batching operations: use redis.pcall with smaller key sets and avoid storing large intermediate results in Lua tables.
    Reduce script memory usage by batching operations: use redis.pcall with smaller key sets and avoid storing large intermediate results in Lua tables.
  2. 90% success Increase maxmemory and enable an eviction policy: CONFIG SET maxmemory 2gb; CONFIG SET maxmemory-policy allkeys-lru. This allows Redis to free memory before the script runs.
    Increase maxmemory and enable an eviction policy: CONFIG SET maxmemory 2gb; CONFIG SET maxmemory-policy allkeys-lru. This allows Redis to free memory before the script runs.
  3. 80% success Use MEMORY USAGE command to identify large keys and delete or archive them before rerunning the script.
    Use MEMORY USAGE command to identify large keys and delete or archive them before rerunning the script.

中文步骤

  1. Reduce script memory usage by batching operations: use redis.pcall with smaller key sets and avoid storing large intermediate results in Lua tables.
  2. Increase maxmemory and enable an eviction policy: CONFIG SET maxmemory 2gb; CONFIG SET maxmemory-policy allkeys-lru. This allows Redis to free memory before the script runs.
  3. Use MEMORY USAGE command to identify large keys and delete or archive them before rerunning the script.

Dead Ends

Common approaches that don't work:

  1. 60% fail

    SCRIPT KILL only stops the script, but the memory pressure remains; the script will fail again on next execution.

  2. 70% fail

    Blindly increasing maxmemory can lead to swap usage or OOM killer on the server; it does not fix the script's memory consumption.

  3. 85% fail

    Disabling eviction can cause Redis to crash with OOM if memory is exhausted; it is not a safe workaround.