A common complaint after a deployment: every logged-in customer is signed out, and carts are empty, including shoppers who were midway through checkout. The usual cause is that Magento’s cache and its customer sessions live in the same Redis database.
Why it happens
bin/magento cache:flush clears the entire cache storage. If sessions are stored in the same Redis database as the cache, the flush deletes them too. Cache growth can also push sessions out when Redis runs short of memory.
Check your setup
Open app/etc/env.php and compare the Redis database numbers in the cache, page_cache and session sections. If the session database matches either cache database, they are shared.
How to fix it
Give each role its own database, for example cache on 0, page cache on 1 and sessions on 2:
bin/magento setup:config:set --session-save=redis --session-save-redis-db=2
bin/magento cache:flush
Make sure the cache and page cache databases are different from 2 as well.
Do the change outside busy hours. Moving sessions to a new database signs everyone out once, but it’s the last time a cache flush will do that.
Even better
On busier stores, run sessions on a separate Redis instance. Use an eviction policy that never removes sessions for that one, and allkeys-lru for the cache instance (see Redis noeviction errors).
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.
