Redis ships with no memory limit. On a Magento server, the cache keeps growing until Redis uses all the free RAM. Then the Linux kernel kills a process to free memory, usually Redis itself or MySQL, and the store goes down without warning.

Check it

redis-cli CONFIG GET maxmemory
redis-cli INFO memory | grep -E 'used_memory_human|maxmemory_human'

maxmemory 0 means no limit.

Set a limit

In /etc/redis/redis.conf, choose a size that leaves enough RAM for MySQL, PHP and search on the same server:

maxmemory 2gb
maxmemory-policy allkeys-lru
sudo systemctl restart redis-server
redis-cli CONFIG GET maxmemory

With allkeys-lru, Redis removes the oldest cache entries when it reaches the limit, instead of growing or failing.

If sessions are in the same Redis

Don’t use allkeys-lru on a Redis that also holds customer sessions, because it could remove active sessions. Put sessions in their own Redis instance with enough memory (see separating sessions and cache).

On AWS ElastiCache

The memory limit is managed for you. Set maxmemory-policy in the parameter group.

Catch it automatically

MageMonitor checks for this every few minutes as part of its Cache Health checks, and alerts you by email, Slack or webhook the moment it appears, with the exact commands to fix it. See MageMonitor for Magento 2.

Related fixes