Redis refuses writes with OOM command not allowed
OOM 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.
Fix it fast
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)'2Match what you see, then jump to its fix
- 1
maxmemory-policy is noeviction and used memory is at the limitThe policy is noeviction, so Redis never frees anythingFix - 2
maxmemory-policy starts with volatile- and the writes still failA volatile policy is set but no key has a TTLFix - 3
Memory 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
- 1
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-policy2Fix
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 REWRITE3Verify
A write succeeds and evicted_keys starts to rise.
redis-cli SET probe 1
redis-cli INFO stats | grep evicted_keysConfirmed by redis.io
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 keyspace2Fix
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-lru3Verify
The keyspace line shows keys with an expiry count, or writes succeed after the policy change.
redis-cli INFO keyspaceConfirmed by redis.io
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.12Fix
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 2gb3Verify
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
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
Jedis cannot borrow a connection from its pool
Caused by: java.net.SocketTimeoutException
The pool could not give the code a working connection in time.
3 causes, each with a fixDatabases
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 fixDatabases
node-redis throws The client is closed when you send a command
ClientClosedError: The client is closed
node-redis throws ClientClosedError when the client's socket is not open.
3 causes, each with a fixDatabases
redis-cli says Connection refused on a Mac with Homebrew
Could not connect to Redis at 127.0.0.1:6379: Connection refused
Connection refused means nothing is listening on that port.
3 causes, each with a fixDatabases
Redis cannot save dump.rdb because it is not allowed to write there
Permission denied
Redis writes its snapshot into the directory set by dir, using the account the server runs as.
3 causes, each with a fixDatabases
Redis answers every command with LOADING after a restart
(error) LOADING Redis is loading the dataset in memory
LOADING means the server is up but still reading its RDB or AOF file back into memory, so it refuses most commands until that finishes.
3 causes, each with a fix