Redis: OOM command not allowed when used memory > 'maxmemory'
Educational use only. Content explains errors and defensive fixes for systems you own or are authorised to test. Do not use any technique here to access data, accounts, or networks without permission.
Root Cause
Redis is an in-memory datastore. This error occurs when you attempt a write operation (like `SET`, `HSET`, `LPUSH`) but the server has reached its configured `maxmemory` limit. Redis protects itself from crashing the host operating system by refusing new data. If an eviction policy isn't configured (or is set to `noeviction`), Redis will continue to serve read requests but will reject all writes until memory is freed manually.
Fix / Solution
You have several options depending on your architecture. You can increase the `maxmemory` limit in `redis.conf` if the server has physical RAM available. Alternatively, you can configure an eviction policy (like `allkeys-lru` or `volatile-lru`) so Redis automatically deletes older or less important keys to make room for new ones. Finally, you can manually delete unnecessary keys or set a Time-To-Live (TTL) on your keys using `EXPIRE` so they clean themselves up.
Code Snippet
# ❌ Redis blocks write command
SET session_123 "data"
# (error) OOM command not allowed...
# ✅ Fix 1: Configure eviction policy in redis.conf
maxmemory 2gb
maxmemory-policy allkeys-lru
# ✅ Fix 2: Always set an expiration (TTL) on volatile data
SETEX session_123 3600 "data"