ERM redis resource_error ai_generated true

ERR 运行脚本错误(调用 f_<sha>):@user_script: <行>: -OOM 当已用内存超过 'maxmemory' 时不允许执行命令

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

ID: redis/lua-script-oom

其他格式: JSON · Markdown 中文 · English
85%修复率
90%置信度
1证据数
2023-11-20首次发现

版本兼容性

版本状态引入弃用备注
Redis 6.2.0 active
Redis 7.0.0 active
Redis 7.2.0 active

根因分析

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

English

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

generic

官方文档

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

解决方案

  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.

无效尝试

常见但无效的做法:

  1. 60% 失败

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

  2. 70% 失败

    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% 失败

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