Redis to Valkey: Configuring Magento 2 Cache and Sessions
Adobe's requirements for the latest Magento 2.4.6, 2.4.7 and 2.4.8 patches list Valkey 8.1 instead of Redis, and Magento 2.4.9 requires Valkey 9. On 2.4.8 and earlier you keep the redis options in setup:config:set and point them at a Valkey server; 2.4.9 adds dedicated valkey options for the cache, page cache and sessions.
If your store runs the latest patch of Magento 2.4.6, 2.4.7 or 2.4.8, Adobe's system requirements now list Valkey 8.1 for cache and sessions and mark Redis as not supported. Magento 2.4.9 requires Valkey 9, and its setup commands change as well.
Valkey is an open-source fork of Redis that speaks the same protocol, so the move is mostly configuration rather than code. If you want the background on what Magento stores in its cache and sessions first, start with the Redis, RabbitMQ and indexing lesson (Arabic, with English code).
Which Magento versions need Valkey?
| Magento version | Cache and sessions per Adobe's requirements | setup:config:set options |
|---|---|---|
| 2.4.6-p15, 2.4.7-p10, 2.4.8-p5 | Valkey 8.1; Redis not supported | redis options pointed at a Valkey server |
| 2.4.9 | Valkey 9 | valkey options |
| Earlier patches such as 2.4.6-p14 and 2.4.8-p4 | Redis 7.2 or Valkey 8 | redis options |
How do you configure cache and sessions on 2.4.8 and earlier?
The options are still named redis; point them at your Valkey server:
bin/magento setup:config:set --cache-backend=redis --cache-backend-redis-server=127.0.0.1 --cache-backend-redis-db=0
bin/magento setup:config:set --page-cache=redis --page-cache-redis-server=127.0.0.1 --page-cache-redis-db=1
bin/magento setup:config:set --session-save=redis --session-save-redis-host=127.0.0.1 --session-save-redis-log-level=4 --session-save-redis-db=2Each type gets its own database number: 0 for the default cache, 1 for the page cache and 2 for sessions. The commands write the settings to app/etc/env.php. If Varnish handles your full page cache, you can skip the page cache line; see setting up Varnish full page cache.
How do you configure them on Magento 2.4.9?
bin/magento setup:config:set --cache-backend=valkey --cache-backend-valkey-server=127.0.0.1 --cache-backend-valkey-db=0
bin/magento setup:config:set --page-cache=valkey --page-cache-valkey-server=127.0.0.1 --page-cache-valkey-db=1
bin/magento setup:config:set --session-save=valkey --session-save-valkey-host=127.0.0.1 --session-save-valkey-db=2Magento 2.4.9 moved its cache layer to Symfony Cache, which changed the shape of the env.php configuration. Don't copy an old snippet from another article or project: run the commands and read the file they generate. According to Adobe, using igbinary with Symfony Cache makes cache entries about 45% smaller and 5–10% faster.
Which settings make a performance difference?
- Separate cache from sessions: different database numbers at minimum, and a dedicated instance for each where you can.
- Persist sessions only: enable RDB or AOF on the session instance. Cache can be rebuilt, so it doesn't need persistence.
- Memory: size the cache instance at least as large as your
var/cachedirectory. - Lua: keep
use_lua=0anduse_lua_on_gc=1. Enablinguse_luaon 2.4.7 and 2.4.8 can corrupt the cache. - Session concurrency: on large clusters, set
max_concurrencyto at least 10% of your PHP processes. - Several web nodes: use the L2 cache (
RemoteSynchronizedCache) and preload keys such asGLOBAL_PLUGIN_LISTandSYSTEM_DEFAULTwithpreload_keys, including your store's id_prefix.
Adobe's recommended Valkey server settings:
lazyfree-lazy-eviction yes
lazyfree-lazy-expire yes
lazyfree-lazy-server-del yes
lazyfree-lazy-user-del yes
replica-lazy-flush yesWhere this cache sits in a larger store's architecture, next to the database and message queues, is covered in the e-commerce system design lesson (Arabic). Magento's own cache types are explained in the database and performance lesson (Arabic).
How do you move a live store from Redis to Valkey?
- Provision the Valkey version your Magento release requires, and rehearse the switch on staging.
- Pick a low-traffic window: existing sessions don't carry over, so signed-in customers will need to log in again.
- Run the
setup:config:setcommands for your version. - Flush the cache with
bin/magento cache:flush. - Confirm connectivity with
valkey-cli ping, and watch traffic withvalkey-cli monitorfor a few seconds only, since it is expensive on a busy server. - Watch page load times and error logs for the first few hours.
Valkey migration checklist
- The Valkey version matches your Magento release's requirements
- Cache, page cache and sessions use separate databases or instances
- Persistence is enabled on the session instance only
-
use_lua=0anduse_lua_on_gc=1 -
env.phpwas reviewed after running the commands, not copied from an old source - The switch ran in a low-traffic window after a staging rehearsal
-
cache:flushhas run andvalkey-cli pingreturns PONG
Sources
Technical claims in this article were checked against:
Frequently asked questions
Does Magento 2 still support Redis?
Adobe's requirements for the latest 2.4.6, 2.4.7 and 2.4.8 patches mark Redis as not supported and list Valkey 8.1 instead, and Magento 2.4.9 requires Valkey 9. Earlier patches still listed Redis 7.2.
How do I store Magento 2.4.9 sessions in Valkey?
Run bin/magento setup:config:set --session-save=valkey --session-save-valkey-host=127.0.0.1 --session-save-valkey-db=2, adjusting the host and database number for your server, then review what was written to app/etc/env.php.
Do I need code changes to use Valkey instead of Redis on Magento 2.4.8?
No. On 2.4.8 and earlier you use the same redis options in setup:config:set and point them at the Valkey server, because Valkey speaks the same protocol.
Why should Magento cache and sessions be separated?
They have different needs: cache can be flushed and rebuilt, so it needs no persistence, while losing sessions logs customers out. Adobe recommends separate database numbers at minimum, separate instances where possible, and persistence only for sessions.
What is use_lua in Magento's cache configuration?
It runs Lua scripts inside the cache server. Adobe recommends use_lua=0 and use_lua_on_gc=1, and warns that enabling use_lua on 2.4.7 and 2.4.8 can corrupt the cache.
Related lessons (Arabic)
These free lessons are written in Arabic; code and technical terms are in English.