Fix Redis OOM command not allowed when used memory > 'maxmemory'
Redis OOM command not allowed means maxmemory is reached and no key can be evicted. Check maxmemory-policy and TTLs, then change the policy or the limit.
OOM command not allowed when used memory > 'maxmemory'.Memory use is above maxmemory and the policy leaves no key that may be evicted, so Redis refuses commands that add data. It happens with the default noeviction policy, or with a volatile-* policy when no key has a TTL. For a cache, switch the policy to allkeys-lru; for data that must not be dropped, raise the limit.
[1] Check the limit and the policy. If used_memory_human is at or above maxmemory_human and the policy is noeviction, this error follows.
$ redis-cli INFO memory | grep -E '^(used_memory_human|maxmemory_human|maxmemory_policy):'used_memory_human:3.04Mmaxmemory_human:3.00Mmaxmemory_policy:noeviction$ redis-cli INFO stats | grep -E '^(evicted_keys|total_eviction_exceeded_time):'evicted_keys:0total_eviction_exceeded_time:237evicted_keys:0 means nothing has been evicted so far. Per the docs, noeviction keeps all keys and returns an error for commands that add data, while read-only commands still work (Key eviction). In the test, GET and DBSIZE still worked.
[2] To see where it starts failing, push a stream of writes and find the first error. Below, 1,000-byte values were written with maxmemory 3mb; the first 1,906 succeeded and the rest were refused.
$ seq 1 4000 | awk -v v="$V" '{print "SET user:" $1 " " v}' | redis-cli > fill.out$ grep -c '^OK$' fill.out1906$ grep -m1 -v '^OK$' fill.outOOM command not allowed when used memory > 'maxmemory'.$V is a 1,000-byte string. On a real service, match the time this message first appeared in the app log with the write volume at that moment.
[3] Find what uses the memory. --memkeys scans keys and reports the biggest, and MEMORY USAGE gives one key's real size in bytes.
$ redis-cli --memkeys -i 0.01 2>&1 | grep -E 'Biggest|found|keys with|Total' | head -8[00.00%] Biggest string found so far "user:1736" with 1080 bytesTotal key length in bytes is 16047 (avg len 8.42)Biggest string found "user:1736" has 1080 bytes$ redis-cli MEMORY USAGE user:11072A key with a 1,000-byte value takes 1,072 bytes. Add that per-key overhead when you check whether your sizing adds up. -i 0.01 sleeps that many seconds per 100 SCAN calls to keep load low on a production server (redis-cli).
[4] If you use a volatile-* policy, check that keys actually have TTLs. The docs state that volatile-xxx policies behave like noeviction when no keys have an expiration. Switching to volatile-lru did not help in the test:
$ redis-cli CONFIG SET maxmemory-policy volatile-lruOK$ redis-cli SET one-more xOOM command not allowed when used memory > 'maxmemory'.$ redis-cli INFO keyspace# Keyspacedb0:keys=1906,expires=0,avg_ttl=0,subexpiry=0expires=0 means there are no eviction candidates. Check in the code whether the app sets a TTL, for example SET key value EX <seconds>.
[5] For a cache, switch the policy to allkeys-lru. It applies immediately and evicts the least recently used keys as writes come in. Do not do this on an instance that also holds data that must not disappear (source-of-truth data, queues, locks) — those keys get evicted too.
$ redis-cli CONFIG SET maxmemory-policy allkeys-lruOK$ seq 4001 4500 | awk -v v="$V" '{print "SET user:" $1 " " v}' | redis-cli | sort | uniq -c 500 OK$ redis-cli INFO stats | grep -E '^evicted_keys:'evicted_keys:674$ redis-cli DBSIZE1733Writing 500 more keys evicted 674. Redis evicts until usage is back under the limit, so it can remove more keys than you add. To revert, run CONFIG SET maxmemory-policy noeviction (evicted keys do not come back).
[6] If data must not be dropped, raise the limit. maxmemory can also change at runtime. Keep it below the server's real memory; the docs advise leaving room for replication and persistence buffers when you use them (mem_not_counted_for_evict in INFO memory).
$ redis-cli CONFIG SET maxmemory-policy noevictionOK$ redis-cli CONFIG SET maxmemory 6mbOK$ redis-cli SET one-more2 xOK[7] Write the new values to the config file as well. CONFIG SET is lost on restart. CONFIG REWRITE only works when the server was started from a config file; a container started without one refuses it.
$ redis-cli CONFIG REWRITEERR The server is running without a config fileIn that case create a redis.conf with maxmemory and maxmemory-policy and start from it, or pass them as startup options such as redis-server --maxmemory 6mb --maxmemory-policy noeviction.
If writes are blocked with MISCONF … unable to persist to disk instead, it is a save failure, not memory. See Redis MISCONF unable to persist to disk. If memory is fine and only one key returns WRONGTYPE Operation against a key, the key's data type does not match the command — see Redis WRONGTYPE Operation against a key.
For latency caused by persistence and fork rather than the memory limit, see Redis 7 latency tuning: appendfsync, THP, LATENCY DOCTOR, SLOWLOG.