How to Fix “Memory Full” in Redis (2026 Guide)
The Short Answer
To fix the “Memory Full” error in Redis, adjust the eviction policy to remove less recently used (LRU) keys when the memory limit is reached, which can be done by setting the maxmemory-policy configuration option to allkeys-lru. This change can reduce the memory usage from 100% to 80% within 10 minutes, depending on the workload and configuration.
Why This Error Happens
- Reason 1: The most common cause of the “Memory Full” error in Redis is when the
maxmemorylimit is reached, and the eviction policy is not set to remove keys, resulting in a cache error. For example, if themaxmemorylimit is set to 4GB and the Redis instance is handling 10,000 requests per minute, the memory usage can increase rapidly, leading to the error. - Reason 2: An edge case cause of this error is when the Redis instance is configured to use a custom eviction policy that is not suitable for the specific use case, such as using the
volatile-lrupolicy with a high number of persistent keys. This can lead to a situation where the Redis instance is unable to evict keys, resulting in the “Memory Full” error. - Impact: The “Memory Full” error can cause a cache error, leading to a significant decrease in performance and potentially resulting in errors for users. For instance, if the Redis instance is used as a cache layer for a web application, the error can cause the application to slow down or become unresponsive, leading to a poor user experience.
Step-by-Step Solutions
Method 1: The Quick Fix
- Go to Redis Config > Memory and set the
maxmemorylimit to a lower value, such as 2GB, to reduce the memory usage. - Toggle the
maxmemory-policyoption toallkeys-lruto enable the eviction of less recently used keys when the memory limit is reached. - Refresh the Redis instance to apply the changes.
Method 2: The Command Line/Advanced Fix
To configure the eviction policy using the Redis command line, run the following command:
| |
This will set the eviction policy to remove less recently used keys when the memory limit is reached. Additionally, you can configure the maxmemory limit using the following command:
| |
This will set the maxmemory limit to 2GB.
Prevention: How to Stop This Coming Back
To prevent the “Memory Full” error from occurring in the future, configure the Redis instance with the following best practices:
- Set the
maxmemorylimit to a reasonable value based on the available memory and workload. - Use the
allkeys-lrueviction policy to remove less recently used keys when the memory limit is reached. - Monitor the Redis instance’s memory usage and adjust the configuration as needed.
- Consider using Redis Cluster to distribute the data across multiple nodes and increase the overall memory capacity.
If You Can’t Fix It…
[!WARNING] If Redis keeps crashing due to the “Memory Full” error, consider switching to Memcached, which handles eviction policies natively without these errors. However, note that Memcached has its own set of limitations and may not be suitable for all use cases.
FAQ
Q: Will I lose data fixing this?
A: The risk of data loss when fixing the “Memory Full” error in Redis depends on the eviction policy used. If the allkeys-lru policy is used, Redis will remove less recently used keys, which may result in the loss of some data. However, if the volatile-lru policy is used, only keys with an expiration time will be removed, reducing the risk of data loss.
Q: Is this a bug in Redis?
A: The “Memory Full” error is not a bug in Redis, but rather a configuration issue. Redis provides several eviction policies to handle memory limits, and it is up to the user to configure the instance correctly. The error has been present in Redis since version 2.2, and the recommended solution is to adjust the eviction policy to suit the specific use case. In Redis version 6.0 and later, the maxmemory limit is set to 0 by default, which means that Redis will not limit its memory usage. However, this can lead to the “Memory Full” error if the instance is not configured correctly.
📚 Continue Learning
Check out our guides on Redis and Memory Full.