Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs and geospatial indexes with radius queries. Redis has built-in replication, Lua scripting, LRU eviction, transactions and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.
Configure Redis Cache for Magento 2
To enable caching in redis, extend your <root dir>/app/etc/env.php with the following snippet. Add this in between the cache keys. (Without the cache key in the snippet)
'cache' => array(
'frontend' => array(
'default' => array(
'backend' => 'Cm_Cache_Backend_Redis',
'backend_options' => array(
'server' => '127.0.0.1',
'port' => '6379',
),
),
),
),
Now flush your cache:</>
rm -rf <root dir>/var/cache/* redis-cli flushall
Configure Redis Full Page Caching for Magento 2
To enable page caching redis, extend your <root dir>/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.
'cache' => array (
'frontend' => array (
'default' => array (
'backend' => 'Cm_Cache_Backend_Redis',
'backend_options' => array (
'server' => '127.0.0.1',
'port' => '6379',
),
),
// Start of snippet
'page_cache' => array (
'backend' => 'Cm_Cache_Backend_Redis',
'backend_options' => array (
'server' => '127.0.0.1',
'port' => '6379',
'database' => '1',
'compress_data' => '0',
),
),
// End of snippet
),
),
Now flush your cache:
rm -rf <root dir>/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
## Flush using n98-magerun2
n98-magerun2 cache:flush
## Flush using magento cli
cd <root dir> && php bin/magento cache:flush
To flush all sessions, caches etc (flush the full redis instance), use the following command:
redis-cli flushall
Troubleshooting
A more extended how-to about configuring redis caches can be found on the magento help pages
Thanks for sharing this guide, I was having issue with my Magento store, for Magento I was using full page cache and migrated to Magento 2, Here’s another guide which helped me to fix redis cache, https://www.cloudways.com/blog/how-to-configure-redis-magento-backend/