MAGENTO

How to configure redis cache in Magento2 using the Unix Socket

Redis cache can be configured in two ways.

  1. Configure caching by editing the file env.php
  2. Using the CLI tool

For Example

Redis Cache is running in the following sockĀ  /var/run/redis-multi.redis/redis.sock

Configure caching by editing the file env.php

Below lines needs to add in env.php file.

‘cache’ => [
‘frontend’ => [
‘default’ => [
‘id_prefix’ => ‘8ad_’,
‘backend’ => ‘Cm_Cache_Backend_Redis’,
‘backend_options’ => [
‘server’ => ‘/var/run/redis-multi.redis/redis.sock’,
‘database’ => ‘0’,
‘port’ => ‘0’,
‘password’ => ”
]
],
‘page_cache’ => [
‘id_prefix’ => ‘8ad_’,
‘backend’ => ‘Cm_Cache_Backend_Redis’,
‘backend_options’ => [
‘server’ => ‘/var/run/redis-multi.redis/redis.sock’,
‘database’ => ‘1’,
‘port’ => ‘0’,
‘compress_data’ => ‘0’,
‘password’ => ”
]
]
]
],

Using CLI tool

Below are commands which we used to configure the redis cache in Magento2

Cache

php bin/magento setup:config:set –cache-backend=redis –cache-backend-redis-server=/var/run/redis-multi.redis/redis.sock –cache-backend-redis-db=0 –cache-backend-redis-port=0;

PageCache

php bin/magento setup:config:set –page-cache=redis –page-cache-redis-server=/var/run/redis-multi.redis/redis.sock –page-cache-redis-db=1 –page-cache-redis-port=0;

Free Web Hosting