// Redis error reference

OOM: Memory limit reached

The dataset reached the maxmemory limit and the eviction policy cannot free enough memory, so Redis refuses write commands.

Error prefix
OOM
类别
Memory and persistence
错误信息
OOM command not allowed when used memory > 'maxmemory'.

它的意思

OOM is the write-path refusal when used_memory is over maxmemory and the configured maxmemory-policy cannot free enough: noeviction evicts nothing by definition, and even an allkeys policy can fail when the incoming write is larger than what eviction can reclaim. Read commands keep working, and so do commands without the deny-oom flag, such as DEL; a SET is refused at the limit even when the new value is smaller.

The message names the two knobs precisely: the ceiling is maxmemory and the behavior at the ceiling is maxmemory-policy. Which one to change depends on what the data is: a cache wants an eviction policy; a system of record wants more memory or a smaller dataset.

常见原因

  • maxmemory is set and the working set grew past it, with the policy at its default of noeviction.
  • An allkeys or volatile policy still could not free enough for the incoming write.
  • A single very large value arrives at a moment when eviction has already freed everything it can.

Find the cause

INFO memory
# used_memory versus maxmemory, and the policy in force
INFO stats | grep evicted
# How often eviction already ran to make room
redis-cli --bigkeys
# Where the bytes are: the largest keys by type

maxmemory policies at the limit

noevictionThe default. Write commands are refused with OOM, including ones that would not grow memory; reads keep working.
allkeys-lru / allkeys-lfuEvicts the least recently or least frequently used key, across all keys, to fit the write.
volatile-*Evicts only keys with a TTL. When no key has one, it behaves like noeviction.
allkeys-random / volatile-randomEvicts a random key from the eligible set.

如何修复它

  1. See where you stand before changing anything:

    INFO memory
    # used_memory_human, maxmemory_human, maxmemory_policy
    CONFIG GET maxmemory
  2. For a cache, let Redis free space itself by switching the policy:

    CONFIG SET maxmemory-policy allkeys-lru
  3. For data that must not be evicted, raise the limit or shrink the dataset, then persist the change:

    CONFIG SET maxmemory 2gb
    CONFIG REWRITE

Other ways to handle it

Split by tier: keep evictable data such as sessions and caches in one instance with allkeys-lru, and durable data in another with noeviction plus alerts on used_memory. On the client, tolerate OOM for best-effort writes but never for ledger-style ones.

安全地复现它

redis-server --port 7306 --maxmemory 2mb --maxmemory-policy noeviction --save '' &
head -c 3000000 /dev/zero | tr '\0' 'a' | redis-cli -p 7306 -x SET big
# (error) OOM command not allowed when used memory > 'maxmemory'.

问题

Why do reads still work when writes get OOM?

The limit guards memory growth. Reads are not flagged to be refused at the limit, so Redis serves them, while write commands flagged deny-oom are refused whether or not they grow the dataset.

What does maxmemory 0 mean?

No Redis-side limit: the process grows until the operating system stops it. The OOM refusal only applies when maxmemory is set to a byte value.

相关错误

More memory and persistence errors

代码和消息文本来自 Redis documentation and source code。浏览完整的 Redis error list 或者 搜索每个数据库错误.

// 错误更少,修复更快

Work on Redis in SQLly

A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for Redis and the other databases you use.

本页文字和数据: CC BY 4.0,请注明出处 SQLly (sqlly.app)。 代码和 SQL 片段: MIT. 许可详情 引用的错误消息文本归其数据库厂商所有。