Australian cloud for business software — built and run in Sydney since 2002

NetLeverage
NetLeverage

Redis OOM command not allowed when used memory > 'maxmemory'

Technical article
Troubleshooting

About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.

The error OOM command not allowed when used memory > 'maxmemory'. comes from Redis itself, not from the Linux kernel. Redis has a memory limit (maxmemory), it is at that limit, and it cannot free enough by evicting keys, so it refuses commands that would add data. Reads still work. The fix is a decision about what Redis is for: evict old keys (a cache), give it more memory, or hold less data.

What the error means

In the Redis 8.0 source the error reply is -OOM command not allowed when used memory > 'maxmemory'. Redis builds it when maxmemory is non-zero, an attempt to evict keys has failed, and the command is one flagged as increasing memory use. The same text is in the current unstable branch.

The Redis eviction documentation explains the settings behind it:

  • maxmemory is the memory limit for the dataset. Setting it to zero means no limit; that is the default on 64-bit systems.
  • maxmemory-policy chooses what happens at the limit. The default in redis.conf is noeviction: keys are not evicted and the server returns an error for commands that would cache new data, while commands that only read existing data work as normal.
  • The volatile-xxx policies (volatile-lru, volatile-lrm, volatile-lfu, volatile-random, volatile-ttl; the 8.0 redis.conf does not list volatile-lrm, the current documentation does) evict only keys that have an expiry. The eviction page says they behave like noeviction if no keys have an associated expiration. The redis.conf file adds that with any policy, when there are no suitable keys for eviction, Redis returns an error on write operations that require more memory (its examples are SET, INCR, HSET, LPUSH, SUNIONSTORE, SORT with STORE, and EXEC if the transaction contains such a command).
  • A command that adds a lot of data in one go, such as a big set intersection stored into a new key, can temporarily exceed the limit by a large amount.
  • When replication or persistence is on, the buffers for replicas and the append-only file are not included in the figure compared with maxmemory. INFO reports that amount as mem_not_counted_for_evict. So the figure Redis compares with maxmemory is used_memory without that amount, and a used_memory that is above maxmemory by roughly mem_not_counted_for_evict does not by itself mean the dataset has crossed the limit.

Likely causes

Cause What you see How to confirm
Policy is noeviction and the dataset has reached maxmemory Writes fail, reads work, evicted_keys stays at 0 INFO memory shows maxmemory_policy:noeviction and used memory at the limit
A volatile-xxx policy but most keys have no expiry Writes fail although a policy is set INFO keyspace shows expires far below keys
maxmemory set lower than the working set A recently lowered limit, or data that grew over time Compare used_memory with maxmemory and the growth trend
One or a few very large keys Memory jumps after a feature release redis-cli --bigkeys, or MEMORY USAGE on a suspect key (it reports the bytes a key and its value need)
A single command adds a lot of data at once An error right after one large operation The failing command in the application log
Data that should expire never does Steady growth, TTL not set by the application TTL on a sample key returns -1 (the key exists but has no expiry); INFO keyspace expires is low

Prove the cause before changing anything

All of these are read-only.

1. Read the limit and policy.

redis-cli CONFIG GET maxmemory
redis-cli CONFIG GET maxmemory-policy

2. Read memory use.

redis-cli INFO memory

The INFO page defines used_memory as the total number of bytes allocated by Redis, maxmemory as the value of the configuration directive, maxmemory_policy as the value of maxmemory-policy, and mem_not_counted_for_evict as used memory not counted for key eviction (transient replica and AOF buffers). The eviction page adds that used_memory_dataset is the memory used for cached data, and that if it is greater than maxmemory, the difference is the amount by which maxmemory has been exceeded.

3. See whether keys can expire.

redis-cli INFO keyspace

For each database, the page says a line dbXXX: keys=XXX,expires=XXX,avg_ttl=XXX,subexpiry=XXX is added. A large keys with a small expires explains why a volatile-xxx policy cannot free memory.

4. See what was rejected and what was evicted.

redis-cli INFO stats
redis-cli INFO commandstats

evicted_keys is the number of keys evicted because of the maxmemory limit. The eviction page says the commandstats section reports the number of times each command was rejected, which helps you find which commands the limit is stopping. The INFO page describes the rejected_calls field as the number of rejected calls.

5. Find the biggest keys. The Redis CLI page says redis-cli --bigkeys scans the dataset for big keys using SCAN, so it can run against a busy server, and notes -i 0.1 to sleep between batches. Run it off peak anyway.

redis-cli --bigkeys

Fix

Pick the fix that matches what the data is.

If Redis is a cache and any key can be rebuilt: choose an eviction policy. The eviction page says allkeys-lru is a good default if you have no reason to prefer another, and describes the other policies. Save the current value first:

redis-cli CONFIG GET maxmemory-policy

Risk: with an allkeys-xxx policy Redis deletes keys on its own to stay within the limit, including keys your application assumes are permanent, such as sessions or queue entries. Back-out: redis-cli CONFIG SET maxmemory-policy noeviction (or the value you printed); evicted keys are not recoverable.

redis-cli CONFIG SET maxmemory-policy allkeys-lru

If Redis holds data that must not be evicted (queues, sessions, primary data): do not choose an evicting policy. Reduce data, give the application TTLs for data that should expire, or raise maxmemory if the host has the RAM. The Redis administration page advises setting an explicit maxmemory so that Redis reports errors instead of failing when the system's memory is nearly full, and says to calculate for Redis overhead and fragmentation: if you think you have 10 GB free, set it to 8 or 9.

Save the limit first:

redis-cli CONFIG GET maxmemory

Risk: a limit above the host's real free memory lets Linux's out-of-memory killer terminate Redis, which loses unsaved data. Leave room for copy-on-write during a background save and for buffers. Back-out: redis-cli CONFIG SET maxmemory with the value you printed. The example syntax on the eviction page is CONFIG SET maxmemory 100mb. The units note in redis.conf says 1g is 1,000,000,000 bytes but 1gb is 1024 × 1024 × 1024 = 1,073,741,824 bytes, so read the unit carefully. The 3gb below is only an example value.

redis-cli CONFIG SET maxmemory 3gb

To keep a setting across restarts, edit redis.conf. Copy it first, for example cp -p /etc/redis/redis.conf /etc/redis/redis.conf.2026-11-20.bak (the path depends on your install). Re-read your edit before restarting. Disruptive step: restarting Redis drops every client connection. If persistence is on, Redis reloads data from its RDB or AOF file, and anything written after the last save is lost; if persistence is off, the data is gone. Back-out: copy the .bak file back over redis.conf and restart again. The CONFIG REWRITE page describes an alternative that rewrites the file the server was started with, applying minimal changes; it also changes the file, so make the same copy first.

To reduce data: this means setting expiries on keys and removing abandoned key families, so save first. Print the location with redis-cli CONFIG GET dir and redis-cli CONFIG GET dbfilename, then copy the snapshot file to a filesystem with room, for example cp -p /var/lib/redis/dump.rdb /mnt/spare/dump.rdb.2026-11-20.bak (use your own paths). The copy holds only what was in the last snapshot.

Risk: removing keys cannot be undone: a deleted key cannot be recovered except from a backup. Back-out: load the copy into a separate Redis instance and have the application owner copy the needed keys back; keys written after the last snapshot cannot be restored.

Have the application set an expiry on keys that should not live forever, and remove abandoned key families through the application, after its owner has agreed. Select the exact keys you mean (for example from the --bigkeys output) and have the owner confirm that exact list before anything is removed.

Example (illustrative): sess01 runs Redis as a session store with maxmemory 2gb, which is 2 × 1,073,741,824 = 2,147,483,648 bytes. Logins fail with OOM command not allowed when used memory > 'maxmemory'. INFO memory shows maxmemory_policy:noeviction and used memory at the limit. INFO keyspace shows db0:keys=1900000,expires=0,avg_ttl=0,subexpiry=0: no session has an expiry. evicted_keys is 0. The cause is that the session library was upgraded and stopped setting a TTL. The team restores the library setting so new sessions expire, and has the application give each of the 1,900,000 existing session keys an expiry, because keys stored without one stay forever. They do not switch to allkeys-lru, because that would log out active users. To clear the error while the expiries take effect, they check that the host has the free RAM and raise maxmemory to 3gb (3 × 1,073,741,824 = 3,221,225,472 bytes). A test write then succeeds, and used memory falls as the sessions expire.

Confirm the fix

Repeat redis-cli INFO memory: used memory should be below maxmemory with headroom, and a test write should succeed. Check INFO commandstats again; rejected_calls for the commands that failed should stop growing. If you chose eviction, watch evicted_keys and the hit rate: the eviction page gives keyspace_hits / (keyspace_hits + keyspace_misses) * 100.

What to watch afterwards

  • used_memory against maxmemory as a percentage, with an alert well before 100%.
  • evicted_keys, and rejected_calls for write commands.
  • The count of keys with and without an expiry in INFO keyspace.
  • The biggest keys after each application release.
  • Host free memory, because maxmemory does not cover the fork used for snapshots or other processes.

Risks and limits

Behaviour here comes from the Redis documentation and the Redis 8.0 source; other versions may differ. An evicting policy deletes data by design. Raising maxmemory without checking the host trades this error for a possible kernel kill; see Linux OOM Killer on a VM: Find the Cause, Set Memory Limits. A failed snapshot is a separate error covered in Redis MISCONF: unable to persist to disk (RDB snapshots failing, writes refused). These commands have not been run or lab-tested.

Sources

  • Key eviction — Redis documentation, no date shown, accessed 20 November 2026
  • INFO — Redis documentation, no date shown, accessed 20 November 2026
  • Redis administration — Redis documentation, no date shown, accessed 20 November 2026
  • Redis CLI — Redis documentation, no date shown, accessed 20 November 2026
  • MEMORY USAGE — Redis documentation, no date shown, accessed 20 November 2026
  • TTL — Redis documentation, no date shown, accessed 20 November 2026
  • CONFIG SET — Redis documentation, no date shown, accessed 20 November 2026
  • CONFIG GET — Redis documentation, no date shown, accessed 20 November 2026
  • CONFIG REWRITE — Redis documentation, no date shown, accessed 20 November 2026
  • server.c, Redis 8.0 branch — Redis source on GitHub, no date shown, accessed 20 November 2026
  • server.c, Redis unstable branch — Redis source on GitHub, no date shown, accessed 20 November 2026
  • redis.conf, Redis 8.0 branch — Redis, no date shown, accessed 20 November 2026