Guide

Set up Valkey or Redis for Magento 2, cache and sessions.

Move Magento's cache and sessions out of files and into Valkey or Redis: one command each, in separate databases, then check and flush the right one. Checked on Nov 5, 2026.

Step 1Check

Make sure Valkey or Redis is running

The latest Magento patches list Valkey 8.1, the open-source fork of Redis. Magento talks to both in the same way, so the commands below work for either.

On your server

valkey-cli ping        # or: redis-cli ping
valkey-cli INFO server | grep version

PONG means the server answers.

Step 2Cache

Send the default cache to database 0

Configuration, layouts, blocks and translations are cached here. One command writes the settings to app/etc/env.php.

On your server

bin/magento setup:config:set --cache-backend=redis \
  --cache-backend-redis-server=127.0.0.1 \
  --cache-backend-redis-port=6379 \
  --cache-backend-redis-db=0

Step 3Cache

Without Varnish: the page cache in database 1

If you do not use Varnish, put the full-page cache in its own database. With Varnish, skip this step: Varnish holds the pages.

On your server

bin/magento setup:config:set --page-cache=redis \
  --page-cache-redis-server=127.0.0.1 \
  --page-cache-redis-db=1

Step 4Sessions

Sessions in database 2

Sessions in Valkey or Redis are faster than files and work across several web servers. Keep them in their own database, so flushing the cache never logs customers out.

On your server

bin/magento setup:config:set --session-save=redis \
  --session-save-redis-host=127.0.0.1 \
  --session-save-redis-db=2

Never run FLUSHALL on a server that holds sessions: it empties every database, carts included.

Step 5Check

Check and flush the right way

Each database should now hold keys. Flush Magento's cache with bin/magento, which only touches the cache databases.

On your server

valkey-cli INFO keyspace
bin/magento cache:flush

Questions, answered.

ShopWhizzy support Magento since 2008

Talk to us
Either. Valkey is the open-source fork of Redis and the version Adobe lists for the latest Magento patches. Magento's configuration is the same for both.
So you can flush the cache without emptying sessions, and see at a glance how big each one is.
In app/etc/env.php, under cache and session. The setup:config:set commands write them for you.
Yes. Cache and sessions run in their own databases on every Magento plan.

Bring your store over. We move it for free.

Pick a plan, pick a platform, and your store is online before the coffee cools.

Prices include VAT. Server support on every plan.