OOM
RedisCRITICALMemory ManagementHIGH confidence

Command not allowed when used memory > 'maxmemory'

Production Risk

High. This error stops all data writes, potentially leading to data loss and application failure.

What this means

This error occurs when Redis has reached its configured 'maxmemory' limit and the current command would allocate more memory. To protect itself, Redis rejects the command.

Why it happens
  1. 1The 'maxmemory' directive is set too low for the application's workload.
  2. 2A memory leak in the application is filling Redis with unnecessary data.
  3. 3An eviction policy (like 'allkeys-lru') is not effectively removing old data to make space for new data.
How to reproduce

A Redis instance with a 100MB maxmemory limit is full, and a client tries to add a new key.

trigger — this will error
trigger — this will error
# Assuming Redis is at its maxmemory limit
SET new_data "..."

expected output

(error) OOM command not allowed when used memory > 'maxmemory'.

Fix 1

Increase the 'maxmemory' limit

WHEN The current limit is genuinely too small for the dataset

Increase the 'maxmemory' limit
CONFIG SET maxmemory 2GB

Why this works

This command dynamically increases the memory limit, allowing new writes to succeed. This should be paired with a permanent change in the redis.conf file.

Fix 2

Configure an appropriate eviction policy

WHEN When Redis is being used as a cache

Configure an appropriate eviction policy
CONFIG SET maxmemory-policy allkeys-lru

Why this works

Setting an eviction policy like 'allkeys-lru' (Least Recently Used) tells Redis to automatically delete less-used keys to make room for new ones, preventing the OOM error.

Fix 3

Identify and remove large or unnecessary keys

WHEN To manually free up memory

Identify and remove large or unnecessary keys
redis-cli --bigkeys
# Use SCAN and MEMORY USAGE to find keys to delete
SCAN 0 COUNT 1000
MEMORY USAGE my_large_key

Why this works

Using Redis's built-in tools can help you find which keys are consuming the most memory so you can investigate if they are still needed.

What not to do

Set maxmemory to 0 (unlimited)

Running Redis without a memory limit on a server can lead to it consuming all available system RAM, causing the Redis process or other critical system processes to be terminated by the OS OOM killer.

Sources
Official documentation ↗

maxmemory and eviction policy implementation

Redis eviction policies

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Redis errors