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

- **ID:** `redis/lua-script-oom`
- **Domain:** redis
- **Category:** resource_error
- **Error Code:** `ERM`
- **Verification:** ai_generated
- **Fix Rate:** 85%

## 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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Redis 6.2.0 | active | — | — |
| Redis 7.0.0 | active | — | — |
| Redis 7.2.0 | active | — | — |

## Workarounds

1. **Reduce script memory usage by batching operations: use redis.pcall with smaller key sets and avoid storing large intermediate results in Lua tables.** (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.
   ```
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.** (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.
   ```
3. **Use MEMORY USAGE command to identify large keys and delete or archive them before rerunning the script.** (80% success)
   ```
   Use MEMORY USAGE command to identify large keys and delete or archive them before rerunning the script.
   ```

## Dead Ends

- **** — SCRIPT KILL only stops the script, but the memory pressure remains; the script will fail again on next execution. (60% fail)
- **** — Blindly increasing maxmemory can lead to swap usage or OOM killer on the server; it does not fix the script's memory consumption. (70% fail)
- **** — Disabling eviction can cause Redis to crash with OOM if memory is exhausted; it is not a safe workaround. (85% fail)
