Command not allowed when used memory > 'maxmemory'
Production Risk
High. This error stops all data writes, potentially leading to data loss and application failure.
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.
- 1The 'maxmemory' directive is set too low for the application's workload.
- 2A memory leak in the application is filling Redis with unnecessary data.
- 3An eviction policy (like 'allkeys-lru') is not effectively removing old data to make space for new data.
A Redis instance with a 100MB maxmemory limit is full, and a client tries to add a new key.
# 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
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
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
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.
✕ 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.
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev