Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

Redis refuses writes with OOM command not allowed

ErrorOOM command not allowed when used memory > 'maxmemory'

Short answer

Redis rejects writes when used memory reaches maxmemory and the eviction policy cannot free any. With the default noeviction policy, or a volatile policy and no keys with a TTL, every write fails while reads keep working. Check maxmemory and the policy, then set an eviction policy, add TTLs or raise the limit.

  • Applies to Redis 7.4, Redis 8
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Read the limit, the policy and the memory actually used. The three values explain which cause applies.

    redis-cli CONFIG GET maxmemory
    redis-cli CONFIG GET maxmemory-policy
    redis-cli INFO memory | grep -E '^(used_memory_human|maxmemory_human|maxmemory_policy)'
  2. 2Match what you see, then jump to its fix

    1. 1maxmemory-policy is noeviction and used memory is at the limitThe policy is noeviction, so Redis never frees anythingFix
    2. 2maxmemory-policy starts with volatile- and the writes still failA volatile policy is set but no key has a TTLFix
    3. 3Memory use is at the limit with a policy that does not apply, or one key type dominatesmaxmemory is too low for the data, or a few keys are hugeFix

What does the error look like?

  • OOM command not allowed when used memory > 'maxmemory'
  • (error) OOM command not allowed when used memory > 'maxmemory'.

Cause 1 of 3

The policy is noeviction, so Redis never frees anything

1Check

noeviction is the default policy. Redis keeps all keys and returns an error to commands that would add data, while commands that only read still work.

redis-cli CONFIG GET maxmemory-policy

2Fix

If the data is a cache, let Redis evict old keys. allkeys-lru is the documented default choice when you have no reason to prefer another policy. Save it in redis.conf too, or it is lost at restart.

redis-cli CONFIG SET maxmemory-policy allkeys-lru
redis-cli CONFIG REWRITE

3Verify

A write succeeds and evicted_keys starts to rise.

redis-cli SET probe 1
redis-cli INFO stats | grep evicted_keys

Confirmed by redis.io

Did this fix it?

Cause 2 of 3

A volatile policy is set but no key has a TTL

1Check

The volatile policies only evict keys that have an expiry. When no key has one they behave like noeviction. Count the keys that carry a TTL.

redis-cli CONFIG GET maxmemory-policy
redis-cli INFO keyspace

2Fix

Give cache keys a TTL when you write them, or switch to an allkeys- policy. Use a volatile policy only when one instance mixes a cache with keys that must stay.

redis-cli SET session:42 data EX 3600
# or
redis-cli CONFIG SET maxmemory-policy allkeys-lru

3Verify

The keyspace line shows keys with an expiry count, or writes succeed after the policy change.

redis-cli INFO keyspace

Confirmed by redis.io

Did this fix it?

Cause 3 of 3

maxmemory is too low for the data, or a few keys are huge

1Check

maxmemory caps the memory used for data. Find the keys that take the most space before you raise it.

redis-cli INFO memory | grep -E '^(used_memory_human|maxmemory_human)'
redis-cli --bigkeys -i 0.1

2Fix

Delete or expire the large keys you do not need, or raise maxmemory. Leave RAM free below the limit: with persistence or replication, buffers use memory that is not counted against maxmemory, and a save can need up to twice the memory in a write-heavy app.

redis-cli CONFIG SET maxmemory 2gb

3Verify

Used memory sits clearly below the limit and writes succeed.

redis-cli INFO memory | grep -E '^(used_memory_human|maxmemory_human)'

Confirmed by redis.io

Did this fix it?

How do I stop it coming back?

  • Set maxmemory explicitly, below the real free RAM, so Redis reports an error instead of the kernel killing it.
  • Choose the policy to match the use: allkeys-lru for a cache, noeviction only where losing a write is worse than failing it.
  • Give every cache key a TTL when you write it.
  • Watch used_memory against maxmemory and alert before they meet.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Databases

node-redis throws ConnectionTimeoutError on connect

Redis Client Error ConnectionTimeoutError

node-redis raises ConnectionTimeoutError when the socket does not connect within socket.connectTimeout, which is 5000 ms by default.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.