Configure Redis in Magento 2

in CachingPerformance

Redis is a caching method which can increase the speed of the backend and frontend of your shop. On Hypernode every customer has access to Redis cache, starting from 64 MB, depending on the plan. This article will explain how to configure Redis on your Magento 2 shop on Hypernode and how to work with redis-cli.

Configure Redis Cache for Magento 2

To enable caching in redis, extend your /data/web/magento2/app/etc/env.php with the following snippet. Add this in between the cache keys. (Without the cache key in the snippet)

A complete env.php configuration example can be found over here

Now flush your cache:

rm -rf /data/web/magento2/var/cache/*
redis-cli flushall

Configure Redis Full Page Caching for Magento 2

To enable page caching redis, extend your /data/web/magento2/app/etc/env.php with the following snippet.
You should paste this in between the cache keys, so leave the cache tag in this snippet out of it.

A complete env.php configuration example can be found over here

And flush your cache:

rm -rf /data/web/magento2/var/cache/*
redis-cli flushall

Flush your caches

To flush your magento cache, clear the redis database corresponding to your configured redis database:


redis-cli -n $db flushdb

Or alternatively use n98-magerun2 or the magento cli tool:

## Flush using n98-magerun2
n98-magerun2 cache:flush

## Flush using magento cli
cd /data/web/magento2 && php bin/magento cache:flush

To flush all sessions, caches etc (flush the full redis instance), use the following command:

redis-cli flushall

Configure Magento 2 to use redis as the session store

You can use redis for storing sessions too! To do so on Magento 2, read the article about storing sessions in redis and configure your shop accordingly.

Troubleshooting

A more extended how-to about configuring redis caches can be found on the magento help pages

1