All posts

Redis for Magento sessions and cache: how a full Redis empties carts

Redis makes Magento fast: cache, full page cache and customer sessions all sit in memory. It is also where a whole class of “my cart emptied itself” reports comes from. The cause is rarely Redis being down. It is Redis being full.

Free checkout scan

Enter your store address. A real browser adds a product to the cart and walks the checkout up to the payment step, like a customer, and shows you every step with a screenshot.

  • Free, no account
  • Stops before payment, no order
  • Nothing to install
· Updated · 3 min read
A memory module on a table

What Magento keeps in Redis

A typical setup uses three separate Redis databases, written by setup:config:set into env.php:

DataDatabaseIf it is lost
Default cache (config, layout, blocks)0Slower pages while it rebuilds
Full page cache1Slower pages while it rebuilds
Customer sessions2Logged out, cart and checkout step lost
bash
bin/magento setup:config:set --cache-backend=redis --cache-backend-redis-db=0
bin/magento setup:config:set --page-cache=redis --page-cache-redis-db=1
bin/magento setup:config:set --session-save=redis --session-save-redis-db=2

Why a full Redis empties carts

When Redis reaches its maxmemory, it applies the eviction policy. With a policy such as allkeys-lru it deletes the least recently used keys, and it does not care which database they live in. A busy catalog fills the cache, Redis makes room, and the sessions of shoppers who paused for a few minutes are gone.

Separate databases share one memory limit

maxmemory and maxmemory-policy belong to the Redis instance, not to a database number. Database 2 is not protected because cache lives in 0 and 1.

With noeviction the opposite happens: Redis refuses writes when it is full, and the store starts throwing errors instead of losing sessions quietly. Neither is acceptable for checkout, which is why sessions belong in their own instance.

Check memory and evictions

Ask the instance that holds the sessions how full it is and whether it has been evicting keys:

bash
redis-cli -p 6379 info memory | grep -E "used_memory_human|maxmemory_human|maxmemory_policy"
redis-cli -p 6379 info stats | grep -E "evicted_keys|rejected_connections"
redis-cli -p 6379 info keyspace
evicted_keys above 0 on the session instance means sessions have been deleted to make room.

A safe setup

  1. Two instances. One for cache and full page cache with allkeys-lru; one for sessions with noeviction and enough memory for peak traffic.
  2. Size the session instance. Sessions are small, but sale days multiply them; leave clear headroom.
  3. Point sessions to it. Set the session host and port in env.php, for example with --session-save-redis-port=6380.
  4. Alert on memory. Warn before the session instance reaches its limit, not after.
bash
# Session instance (6380): never evict, fail loudly instead
redis-cli -p 6380 config set maxmemory 1gb
redis-cli -p 6380 config set maxmemory-policy noeviction
config set lasts until restart; put the same values in that instance’s redis.conf.
Flushing cache must not touch sessions

bin/magento cache:flush clears the cache backends. A redis-cli flushall on a shared instance also logs every customer out.

Catch it from outside

A lost session looks like a working store: pages load, products add to the cart. A check that keeps the cart through checkout, as a real shopper does, is what shows it. Related: full page cache and checkout and checkout performance.

Check your own store now with the free Magento checkout test: it walks the checkout in a real browser and shows the step where it stops.

Find out your checkout broke before your customers do.

Real checkout checks for Magento and WooCommerce · free plan · no card requiredMagento checkout monitoring →
FAQ

Common questions

Still have a question?More answers, and a way to reach us.Support →
01Why do Magento carts empty randomly?

Often because sessions share a Redis instance with the cache, memory fills up, and the eviction policy deletes session keys. Customers are logged out and their cart is gone.

02Should Magento sessions and cache use the same Redis?

Use separate instances. Different database numbers on one instance still share the memory limit and eviction policy.

03What maxmemory-policy should Magento sessions use?

noeviction on a dedicated, properly sized instance, so sessions are never deleted to make room; the cache instance can use allkeys-lru.