# redis.exceptions.ResponseError：-OOM 命令不允许，当已用内存超过 'maxmemory' 时。

- **ID:** `database/redis-maxmemory-policy-eviction-blocked`
- **领域:** database
- **类别:** resource_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Redis 6.2 | active | — | — |
| Redis 7.0 | active | — | — |
| Redis 7.2 | active | — | — |

## 解决方案

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

## 无效尝试

- **Increase maxmemory without addressing the eviction policy or data growth pattern** — Memory will eventually fill up again if the root cause (e.g., unbounded cache growth, no eviction) is not fixed. (80% 失败率)
- **Flush all keys using FLUSHALL or FLUSHDB without restarting or changing config** — While this temporarily frees memory, the same pattern of writes will cause the error to recur unless the eviction policy is adjusted. (70% 失败率)
