Redis 'OOM Command Not Allowed' Error: Find the Cause and Fix
Redis rejecting writes with OOM command not allowed when used memory exceeds maxmemory? Check the policy, find the keys eating memory, and pick a fix that does not lose sessions or queued jobs.
"OOM command not allowed when used memory > 'maxmemory'" means Redis hit its memory limit and its eviction policy told it not to delete anything, so it now rejects every command that would add data. Run INFO memory to confirm, check maxmemory-policy, find what is filling memory (usually keys with no expiry), and then set TTLs, raise the limit, or change the policy to match what you store. Reads and deletes keep working, which is why the app often half-breaks instead of going fully down.
This applies to self-hosted Redis, Docker, ElastiCache, Upstash and any other managed Redis. The commands are the same everywhere. Some managed plans block CONFIG SET, so use the provider dashboard for those steps.
Step 1: Confirm it is a memory limit
The error text comes from Redis itself (Redis docs). Your client library shows it as a failed SET, INCR, LPUSH or HSET. Typical symptoms in a live app:
- Users get logged out or cannot log in (session writes fail).
- Rate limiting throws 500s.
- Background jobs stop being added to the queue.
- A cache stops filling, so the database gets hammered.
Connect with redis-cli and run:
redis-cli INFO memory
redis-cli CONFIG GET maxmemory
redis-cli CONFIG GET maxmemory-policy
Compare used_memory_human with maxmemory_human. If they are close and the policy is noeviction, you have found it. Redis's own guide for this error starts with the same INFO memory check.
Step 2: Understand the policy
maxmemory-policy decides what Redis does at the limit. The default is noeviction: it refuses writes and returns this error. Other policies delete keys instead:
| Policy | What it deletes | Use for |
|---|---|---|
noeviction |
Nothing. Writes fail. | Queues, sessions, anything you cannot lose |
allkeys-lru |
Least recently used key, any key | A pure cache |
volatile-lru |
Least recently used key that has a TTL | Cache plus data without TTL |
volatile-ttl |
Keys closest to expiry | Short-lived data |
Two traps. First, volatile-* policies only touch keys with a TTL. If your keys have none, you still get the OOM error. Second, maxmemory-policy is a server setting. It applies to every logical database on the instance, so putting a cache in database 1 does not protect a queue in database 0 (key eviction docs).
Step 3: Find what is using the memory
Do not raise the limit before you know what is growing. Scan for large keys:
redis-cli --bigkeys
It samples the keyspace and reports the biggest key per type. Recent redis-cli versions also have --memkeys, which ranks by memory. For one key:
redis-cli MEMORY USAGE session:abc123
Now check expiry. Pick a few keys by prefix and look at their TTL:
redis-cli --scan --pattern 'session:*' | head -5 | xargs -n1 redis-cli TTL
-1 means no expiry. A prefix full of -1 values is your leak. Common sources:
- Sessions or tokens saved without an expiry.
- Cache keys written with
SETinstead ofSET key value EX 3600. - Queue libraries keeping completed and failed jobs forever. With BullMQ, set
removeOnCompleteandremoveOnFail(see BullMQ failed jobs: monitor and retry in production). - One huge list, hash or stream that only ever grows.
Step 4: Free memory safely
To get writes working right now, delete a known-disposable prefix, not the whole database:
redis-cli --scan --pattern 'cache:*' | xargs -n 100 redis-cli UNLINK
UNLINK frees memory in the background, so it does not block Redis the way a big DEL can. Avoid FLUSHALL unless Redis holds only a cache. It will also wipe sessions and queued jobs.
If the data is real and the limit is simply too small, raise it for a quick fix (self-hosted):
redis-cli CONFIG SET maxmemory 2gb
Make sure the host has the RAM first. Also update redis.conf or your provider plan, because CONFIG SET is lost on restart unless you persist it.
Step 5: Fix the cause with TTLs
Set an expiry at write time so memory cannot grow without bound. Node.js with ioredis:
// cache entry: 1 hour
await redis.set(`cache:user:${id}`, JSON.stringify(user), "EX", 3600);
// session: 7 days
await redis.set(`session:${sid}`, data, "EX", 60 * 60 * 24 * 7);
Python with redis-py:
r.set(f"cache:user:{user_id}", payload, ex=3600)
For keys that already exist without a TTL, add one in a one-off script:
redis-cli --scan --pattern 'session:*' | xargs -n 100 -I{} redis-cli EXPIRE {} 604800
Run it during a quiet period. It is a lot of commands.
Step 6: Pick the right policy for what you store
Decide by the data, not by the error:
- Only a cache: use
allkeys-lru. Losing a key just means one more database read. - Sessions, queues, locks, rate-limit counters: use
noeviction, and make sure memory has headroom. An eviction policy can silently delete a session or a pending job, which is worse than a loud error. - A mix on one instance: the safest option is two instances, one cache with
allkeys-lruand one for durable data withnoeviction. If you must share, usenoevictionand keep TTLs on everything that can expire.
redis-cli CONFIG SET maxmemory-policy allkeys-lru
Only run that on a cache-only instance. BullMQ also documents noeviction as the required policy for its queues, so a shared Redis with an LRU policy can lose jobs.
Step 7: Alert before the limit, and handle the error
Memory climbs for days, then the app breaks in minutes. Set an alert at a safe level, for example when used_memory passes 80 percent of maxmemory. ElastiCache, Upstash and Redis Cloud all expose memory metrics. AWS also recommends setting TTLs on keys to avoid this error (AWS Knowledge Center).
Also decide what your code does when Redis rejects a write. For a cache, catch the error and carry on without it. For a session store, return a clear error instead of a blank 500. See Redis Upstash errors on serverless for fail-open patterns.
How Relia Helps
Redis memory errors reach users as unrelated symptoms: failed logins, missing jobs, slow pages. Relia watches users, APIs, the database and servers of a live product and joins related signals into one incident explained in plain words, with who was affected and a fix plan with the file and line when there is a stack trace. Setup for Node.js apps is npx relia-sdk@latest init. It does not replace a memory alert on Redis itself, so keep that too. There is a live demo and a Free plan.
FAQ
Does "OOM command not allowed" mean the server ran out of RAM?
Not necessarily. It means Redis reached its own maxmemory setting. The host may still have free RAM. Raising maxmemory can fix it if the machine has room.
Why do reads still work while writes fail?
Redis only rejects commands that would use more memory. Reads and deletes such as GET and DEL still run, so the problem is easy to miss in a quick test.
Is allkeys-lru safe for sessions?
No. Under memory pressure it can delete any key, including active sessions, so users get logged out at random. Use noeviction with headroom for sessions.
Should I just run FLUSHALL?
Only if Redis is a pure cache. It also deletes sessions, queued jobs and locks, and the error returns if the cause (keys without TTL) stays.
How do I stop it happening again?
Set a TTL on every key that can expire, trim queue history, and alert on memory use before the limit.