|
| 1 | +--- |
| 2 | +myst: |
| 3 | + html_meta: |
| 4 | + description: This article explains how to configure Valkey on your Magento 2 shop on Hypernode and how to work with redis-cli or valkey-cli. |
| 5 | + title: How to configure Valkey for Magento 2? | Hypernode |
| 6 | +redirect_from: |
| 7 | + - /ecommerce-applications/magento-2/how-to-configure-valkey-for-magento-2/ |
| 8 | +--- |
| 9 | + |
| 10 | +# How to Enable Valkey for Magento 2 |
| 11 | + |
| 12 | +Valkey is a Redis-compatible in-memory store. On Hypernode, **Valkey-8** is available on Debian Bookworm single-node setups. It is not supported on Debian Buster or on Hypernode Clusters. **Redis remains supported.** |
| 13 | + |
| 14 | +> If you previously used Redis, **no action needed** after enabling it ( **see example below** ), existing Magento settings continue to work with Valkey. |
| 15 | +> |
| 16 | +## Paths |
| 17 | + |
| 18 | +- Logs: `/var/log/valkey/` |
| 19 | +- App-scoped directory on Hypernode: `/data/web/valkey/` |
| 20 | + |
| 21 | +--- |
| 22 | + |
| 23 | +Valkey is Redis-compatible, so your existing Magento `redis` configuration flags work unchanged. |
| 24 | + |
| 25 | +> **Enable Valkey on supported nodes** |
| 26 | +> |
| 27 | +> ```console |
| 28 | +> $ hypernode-systemctl settings valkey_enabled True |
| 29 | +> ``` |
| 30 | +
|
| 31 | +Take a look at the `livelog` command to check the progress on the update job. |
| 32 | +
|
| 33 | +## Redis Tools or Valkey Tools? |
| 34 | +
|
| 35 | +> `redis-cli`and `redis-tools` is symlinked to `valkey-cli` and `valkey-tools` when Valkey is enabled. You can use **either**. Examples below show `redis-cli` with an `or valkey-cli` alternative. |
| 36 | +
|
| 37 | +
|
| 38 | +# First Time Setup - Redis Not Previously Configured |
| 39 | +
|
| 40 | +## Configure Valkey Cache for Magento 2 |
| 41 | +
|
| 42 | +There are two ways to configure the cache. You can run a command that updates `env.php`, or you can edit it yourself. |
| 43 | +
|
| 44 | +## Configure Valkey Cache for Magento 2 Through the Commandline |
| 45 | +
|
| 46 | +Use the following command to enable backend caching: |
| 47 | +
|
| 48 | +```console |
| 49 | +$ cd /data/web/magento2 |
| 50 | +$ bin/magento setup:config:set --cache-backend=redis --cache-backend-redis-server=redismaster --cache-backend-redis-db=1 |
| 51 | +``` |
| 52 | +
|
| 53 | +Now flush your cache: |
| 54 | + |
| 55 | +```console |
| 56 | +$ rm -rf /data/web/magento2/var/cache/* |
| 57 | +$ redis-cli flushall |
| 58 | +# or |
| 59 | +$ valkey-cli flushall |
| 60 | +``` |
| 61 | + |
| 62 | +## Configure Valkey Full Page Caching for Magento 2 |
| 63 | + |
| 64 | +Enable page caching: |
| 65 | + |
| 66 | +```console |
| 67 | +$ cd /data/web/magento2 |
| 68 | +$ bin/magento setup:config:set --page-cache=redis --page-cache-redis-server=redismaster --page-cache-redis-db=2 |
| 69 | +``` |
| 70 | + |
| 71 | +And flush your cache: |
| 72 | + |
| 73 | +```console |
| 74 | +$ rm -rf /data/web/magento2/var/cache/* |
| 75 | +$ redis-cli flushall |
| 76 | +# or |
| 77 | +$ valkey-cli flushall |
| 78 | +``` |
| 79 | + |
| 80 | +## Flush Your Caches |
| 81 | + |
| 82 | +To flush your Magento cache, clear the Valkey database you configured: |
| 83 | + |
| 84 | +```console |
| 85 | +$ redis-cli -n 1 flushdb |
| 86 | +# or |
| 87 | +$ valkey-cli -n 1 flushdb |
| 88 | +``` |
| 89 | + |
| 90 | +Or alternatively use `n98-magerun2` or the Magento cli tool: |
| 91 | + |
| 92 | +```console |
| 93 | +## Flush using n98-magerun2 |
| 94 | +$ n98-magerun2 cache:flush |
| 95 | +## Flush using magento cli |
| 96 | +$ cd /data/web/magento2 && bin/magento cache:flush |
| 97 | +``` |
| 98 | + |
| 99 | +To flush all sessions, caches etc (flush the full instance), use the following command: |
| 100 | + |
| 101 | +```console |
| 102 | +$ redis-cli flushall |
| 103 | +# or |
| 104 | +$ valkey-cli flushall |
| 105 | +``` |
| 106 | + |
| 107 | +## Changing the Compression Library |
| 108 | + |
| 109 | +It is possible to use the compression library 'Snappy' on Hypernode. |
| 110 | + |
| 111 | +In order to use the compression library Snappy for your Valkey cache you can run the following commands: |
| 112 | + |
| 113 | +```console |
| 114 | +$ bin/magento setup:config:set --cache-backend-redis-compression-lib=snappy |
| 115 | +$ # If you use Magento's builtin page cache |
| 116 | +$ bin/magento setup:config:set --page-cache-redis-compression-lib=snappy |
| 117 | +``` |
| 118 | + |
| 119 | +## Configure Magento 2 to Use Valkey as the Session Store |
| 120 | + |
| 121 | +You can use Valkey for storing sessions too. |
| 122 | + |
| 123 | +### Configure Magento 2 to Store Sessions in Valkey |
| 124 | + |
| 125 | +Run the following command: |
| 126 | + |
| 127 | +```console |
| 128 | +$ cd /data/web/magento2 |
| 129 | +$ bin/magento setup:config:set --session-save=redis --session-save-redis-host=redismaster --session-save-redis-db=3 |
| 130 | +``` |
| 131 | + |
| 132 | +Now flush your cache: |
| 133 | + |
| 134 | +```console |
| 135 | +$ redis-cli flushall |
| 136 | +# or |
| 137 | +$ valkey-cli flushall |
| 138 | +``` |
| 139 | + |
| 140 | +### Enable Second Valkey Instance for Sessions |
| 141 | + |
| 142 | +Enable the second instance for sessions: |
| 143 | + |
| 144 | +```console |
| 145 | +$ hypernode-systemctl settings redis_persistent_instance True |
| 146 | +``` |
| 147 | + |
| 148 | +After enabling the second instance change the session port to `6378` and the database to `0`: |
| 149 | + |
| 150 | +```console |
| 151 | +$ cd /data/web/magento2 |
| 152 | +$ bin/magento setup:config:set --session-save-redis-port=6378 --session-save-redis-db=0 |
| 153 | +``` |
| 154 | + |
| 155 | +Furthermore you can add the following line to your crontab to take periodic background snapshots: |
| 156 | + |
| 157 | +``` |
| 158 | +* * * * * redis-cli -p 6378 bgsave |
| 159 | +# or |
| 160 | +* * * * * valkey-cli -p 6378 bgsave |
| 161 | +``` |
| 162 | + |
| 163 | +### Test Whether Your Sessions Are Stored in Valkey |
| 164 | + |
| 165 | +To verify whether your configuration is working properly, first clear your filesystem session store: |
| 166 | + |
| 167 | +```console |
| 168 | +$ rm /data/web/public/var/sessions/* |
| 169 | +``` |
| 170 | + |
| 171 | +Now open the site in your browser and hit `F5` a few times or log in to the admin panel. Then check the configured database: |
| 172 | + |
| 173 | +```console |
| 174 | +$ redis-cli -n 0 keys '*' |
| 175 | +# or |
| 176 | +$ valkey-cli -n 0 keys '*' |
| 177 | +``` |
0 commit comments