| title | Redis OOM Command Not Allowed When Used Memory > maxmemory | |||||
|---|---|---|---|---|---|---|
| slug | redis-oom-command-not-allowed-maxmemory | |||||
| technologies |
|
|||||
| severity | high | |||||
| tags |
|
|||||
| related |
|
|||||
| last_reviewed | 2026-06-27 |
(error) OOM command not allowed when used memory > 'maxmemory'.
-OOM command not allowed when used memory > 'maxmemory'.
Redis returns this error when the dataset has reached the configured maxmemory
limit and the active maxmemory-policy cannot free enough memory to accept a new
write. With the default noeviction policy, Redis never deletes keys to make
room, so once memory is full every write command (SET, LPUSH, HSET, …) is
rejected with OOM. Read-only commands and commands that delete data (DEL,
EXPIRE, TTL) still work.
This is a configuration/capacity condition, not a crash: the instance is healthy but intentionally protecting itself from exceeding its memory budget.
- redis (memory management / eviction)
high — all writes fail while the limit is exceeded. For a cache this degrades hit rate badly; for a primary data store it is a write outage.
maxmemory-policy noeviction(the default) combined with a dataset that has grown tomaxmemory.- The dataset legitimately exceeds the provisioned memory (under-provisioned).
- Keys are written without TTLs, so a cache grows unbounded and an eviction
policy like
allkeys-lruwas expected butvolatile-lruis set (only keys with a TTL are eligible). - A large
replication backlog, client output buffers, or AOF rewrite memory pushesused_memorypast the limit.
Before executing a write, Redis checks whether used_memory exceeds
maxmemory. If it does, it asks the eviction policy to free space. Under
noeviction nothing is evicted, so the check fails and the command is rejected
with OOM. Under a volatile-* policy, only keys that carry an expiration are
candidates — if most keys have no TTL, eviction frees nothing and you still get
OOM. The error is therefore the intersection of how full memory is and
which keys the policy is allowed to evict.
# Used vs configured memory, peak, fragmentation, and eviction stats
redis-cli INFO memory | grep -E 'used_memory:|used_memory_human|maxmemory:|maxmemory_human|maxmemory_policy|mem_fragmentation_ratio'
# Eviction / keyspace-miss counters (rising evicted_keys means the policy is active)
redis-cli INFO stats | grep -E 'evicted_keys|keyspace_misses|expired_keys'
# Current policy and limit
redis-cli CONFIG GET maxmemory
redis-cli CONFIG GET maxmemory-policy
# How many keys exist and how many have a TTL set
redis-cli INFO keyspace
# Biggest keys driving memory use (read-only sampling scan)
redis-cli --bigkeysused_memory_human:4.00G
maxmemory_human:4.00G
maxmemory_policy:noeviction
evicted_keys:0
used_memory at or above maxmemory with maxmemory_policy:noeviction and
evicted_keys:0 confirms the cause. If the policy is volatile-lru but
INFO keyspace shows few keys with expires, eviction has nothing to remove. A
healthy cache shows used_memory below maxmemory and a rising evicted_keys.
-
If Redis is used purely as a cache, switch to an eviction policy that can reclaim memory (this is a
CONFIG SET, run during a maintenance step, not a diagnostic):redis-cli CONFIG SET maxmemory-policy allkeys-lru
Persist it in
redis.confso it survives restart. -
If Redis is a system of record, do not enable eviction — instead raise
maxmemoryor add a replica/shard:redis-cli CONFIG SET maxmemory 8gb
-
Reclaim space immediately by deleting or expiring stale keys (
DEL,EXPIRE,UNLINK). -
Add TTLs to cache writes so keys self-expire.
redis-cli INFO memory | grep -E 'used_memory_human|maxmemory_human'
redis-cli SET diag:probe ok
# Expect: OK (no OOM), with used_memory comfortably below maxmemory.- Choose
maxmemory-policydeliberately:allkeys-lru/allkeys-lfufor caches,noevictiononly for stores you never want silently trimmed. - Always set TTLs on cache keys and monitor
evicted_keysandused_memory. - Provision
maxmemorybelow the host's physical RAM to leave room for forks and buffers.
redis · memory · maxmemory · eviction · production