When a production application or Celery/BullMQ worker crashes with OOM command not allowed when used memory > 'maxmemory', your Redis or Valkey instance is still online and serving read queries—which is why basic TCP/PING health checks falsely report that the service is healthy while every write operation fails. According to AceMQ's August 11, 2026 Enterprise Redis Troubleshooting Guide, SSD Nodes' October 2026 VPS Redis Cache Audit, and Self-Hosted Sentry Issue #3888, this error occurs when used_memory reaches your configured maxmemory ceiling while maxmemory-policy is set to noeviction (the default) or when a volatile-* policy runs out of keys that carry a TTL expiration.
- Immediate Diagnostic Rule: Never restart Redis or run
FLUSHALLfirst—restarting wipesSLOWLOG, resetsINFOcounters, and destroys latency history (AceMQ). - Cache vs Queue Policy Split: Use
allkeys-lfuorallkeys-lrufor pure caches so Redis automatically evicts cold keys (SSD Nodes), but keepnoevictionorvolatile-lrufor job queues (Celery, Sidekiq, BullMQ) so active jobs are never silently deleted (AceMQ). - The
maxmemory 0Kernel OOM Trap: Settingmaxmemory 0removes Redis's internal cap completely, causing the process to grow until the Linux kernel OOM-kills the container—especially during RDB background saves wherefork()copy-on-write can double memory usage (AceMQ). - Production Safe Key Scan: Use
redis-cli --bigkeys -i 0.01andredis-cli --memkeys -i 0.01(which use cursor-basedSCAN) instead ofKEYS *so you never block the single-threaded event loop (AceMQ).
redis.conf, run CONFIG GET maxmemory and CONFIG GET maxmemory-policy inside your container (AceMQ). If the instance is an application or WordPress object cache, switch the policy live with CONFIG SET maxmemory-policy allkeys-lfu (SSD Nodes). If the instance backs Celery or BullMQ workers, audit un-expired keys with redis-cli --memkeys -i 0.01, cap container maxmemory at 70% to 75% of your Docker memory limit to leave headroom for fork() copy-on-write snapshots, and enable vm.overcommit_memory=1 on the Linux host (AceMQ). See our Problem and Solution troubleshooting hub for companion Docker and PostgreSQL fixes.
1. Redis & Valkey Eviction Policies vs Workload Matrix (2026)
Verified against AceMQ's production Redis forensics and Stack Overflow's Redis maxmemory engineering patterns, choosing the wrong maxmemory-policy either halts writes with OOM errors or silently drops persistent job payloads:
maxmemory-policy Setting |
Eviction Behavior When used_memory > maxmemory |
Why It Still Throws OOM Errors | Recommended Production Workload |
|---|---|---|---|
noeviction (Default) |
Never deletes any keys; immediately returns OOM command not allowed on all write commands (SET, LPUSH, XADD) while reads continue (AceMQ) |
By design—every new write is rejected the moment memory hits maxmemory (AceMQ) |
Primary persistent datastores and strict financial/transactional queues where silent key loss is unacceptable (AceMQ) |
volatile-lru / volatile-lfu / volatile-ttl |
Evicts least-recently-used, least-frequently-used, or shortest-TTL keys only among keys that have an EXPIRE (TTL) set (Stack Overflow) |
If non-expiring keys (no TTL) fill 100% of maxmemory, Redis finds zero eviction candidates and reverts to noeviction OOM errors (AceMQ; Stack Overflow) |
Hybrid instances storing both permanent configuration/queue keys (no TTL) and transient session/cache keys (with TTL) |
allkeys-lfu / allkeys-lru |
Evicts least-frequently-used or least-recently-used keys across the entire keyspace regardless of whether a TTL is set (SSD Nodes) | Only throws OOM if a single command attempts to allocate more memory than the entire maxmemory ceiling |
Dedicated application caches, WordPress/Laravel object caches, and rate-limiter buckets (SSD Nodes). Note: redis-cli --hotkeys requires an *-lfu policy (AceMQ) |
2. Step 1: Run the 4-Command Non-Destructive Memory & Keyspace Audit
Do not restart the container or run KEYS * (which blocks Redis's single execution thread across all connected clients) (AceMQ). Open a shell into your Docker host and run these four non-blocking diagnostic commands:
# 1. Inspect used_memory, maxmemory ceiling, fragmentation ratio & eviction policy
docker compose exec redis redis-cli INFO memory
docker compose exec redis redis-cli CONFIG GET "maxmemory*"
# 2. Check how many keys have a TTL vs non-expiring keys (db0:keys=...,expires=...)
docker compose exec redis redis-cli INFO keyspace
docker compose exec redis redis-cli INFO stats | grep -E "evicted_keys|expired_keys"
# 3. Safely scan for oversized keys using cursor-based SCAN throttled by 10ms (-i 0.01)
docker compose exec redis redis-cli --memkeys -i 0.01
docker compose exec redis redis-cli --bigkeys -i 0.01
# 4. Enable the built-in latency monitor (disabled at 0 by default) to catch RDB fork stalls
docker compose exec redis redis-cli CONFIG SET latency-monitor-threshold 100
docker compose exec redis redis-cli SLOWLOG GET 25
fork() Copy-on-Write Doubling: As AceMQ's engineering team documents, Redis takes RDB disk snapshots by calling fork(2). Under heavy write traffic, copy-on-write memory pages can cause the container's physical RAM footprint to climb toward 2x your dataset size—triggering a hard Docker/kernel OOM-kill even when Redis reports only 60% utilization. Always set Redis maxmemory to 65–75% of the container's Docker mem_limit.
3. Step 2: Apply Live Recovery & Harden Your Production docker-compose.yml
To restore write traffic immediately without restarting the container, apply the appropriate runtime CONFIG SET command, then lock the configuration into your docker-compose.yml so it survives container recreations (AceMQ; SSD Nodes):
# Immediate live recovery (zero downtime):
# For a pure cache instance, switch from noeviction to allkeys-lfu and raise ceiling to 1.5GB:
docker compose exec redis redis-cli CONFIG SET maxmemory 1610612736
docker compose exec redis redis-cli CONFIG SET maxmemory-policy allkeys-lfu
docker compose exec redis redis-cli CONFIG REWRITE
Next, update your docker-compose.yml (works identically for Redis 7+ and open-source Valkey 8) so container memory limits, eviction policy, and background save behavior are explicitly bounded (AceMQ; VDS.GURU):
services:
valkey-cache:
image: valkey/valkey:8.0-alpine
container_name: prod-valkey-cache
restart: unless-stopped
# Bind strictly to internal Docker bridge network; never expose 6379:6379 to 0.0.0.0
expose:
- "6379"
command: >
valkey-server
--maxmemory 1536mb
--maxmemory-policy allkeys-lfu
--activedefrag yes
--lazyfree-lazy-eviction yes
--lazyfree-lazy-expire yes
--latency-monitor-threshold 100
--save ""
--appendonly no
deploy:
resources:
limits:
# Give container 2048MB ceiling for 1536MB maxmemory (25% headroom for buffers/fork)
memory: 2048M
healthcheck:
# Verify both PING and that used_memory is below maxmemory
test: ["CMD-SHELL", "valkey-cli ping | grep PONG"]
interval: 10s
timeout: 3s
retries: 3
4. Related Practical Stack Engineering Guides
- Fix container connection drops and restart loops in our Problem and Solution DevOps Troubleshooting Hub.
- Compare self-hosted PaaS engines (Coolify, Dokploy, Kamal 2) in our Open-Source SaaS & Self-Hosting Guides.
- Explore high-speed API caching patterns in our Developer Tools & Infrastructure Benchmarks Archive.