Cache Management for Beginner | How to configure Redis cache in Magento2 | Part6



What is Redis : Remote Dictionary Server (Redis) is an open source, in-memory data structure store, used as a database, cache and message broker. Redis supports different kinds of abstract data structures, such as strings, lists, maps, sets, sorted sets ,etc.

Where Redis cache is store: Redis cache store in server memory RAM / DISK.

How to Install Redis : Using following commands we can install the redis on your server,

  • sudo add-apt-repository ppa:chris-lea/redis-server
  • sudo apt-get update
  • sudo apt-get install redis-server

Note: Depend of OS , the above command may change.

How to Configure Redis cache in Magento2 :

(I).Using Command Line :

Magento is providing option to configure the redis using the command line.

Command : php bin/magento setup:config:set –cache-backend=redis

–cache-backend-redis-<parameter_name>=<parameter_value>

Example : php bin/magento setup:config:set –cache-backend=redis

–cache-backend-redis-server=127.0.0.1

–cache-backend-redis-port=6379

–cache-backend-redis-db=0

–cache-backend-redis-password=****

Regarding Password :We will configure the password directly in file level instead of setting using command line.

Configuration File Path for Redis : /etc/redis/redis.conf

Once after execute the above command , magento automatically add below code snippet into app/etc/env.php file .

(II). Direct File level modification :

1. Open app/etc/env.php

2. Add below code snippet

Sample Code Snippet:

‘cache’ => [

‘frontend’ => [ ‘default’ => [

‘backend’ => ‘Cm_Cache_Backend_Redis’,

‘backend_options’ => [ ‘server’ => ‘127.0.0.1’,

‘database’ => ‘0’,

‘port’ => ‘6379’ ], ],

‘page_cache’ => [ ‘backend’ => ‘Cm_Cache_Backend_Redis’,

‘backend_options’ => [ ‘server’ => ‘127.0.0.1’,

‘port’ => ‘6379’,

‘database’ => ‘1’,

‘force_standalone’ => ‘0’,

‘connect_retries’ => ‘1’,

‘read_timeout’ => ’10’,

‘automatic_cleaning_factor’ => ‘0’,

‘compress_data’ => ‘1’,

‘compress_tags’ => ‘1’,

‘compress_threshold’ => ‘20480’,

‘compression_lib’ => ‘gzip’, ] ] ] ],

Verify Redis cache is working in magento2 :

1. Run below command to monitor the redis cache workflow,

redis-cli monitor

2. Reload the website pages and see if you get below output than the redis cache is working as expect,

Output For Session :

“select” “0”

“hmget” “sess_sgmeh2k3t7obl2tsot3h2ss0p1” “data” “writes”

Output For Page:

“select” “1”

“hget” “zc:k:ea6_GLOBAL__DICONFIG” “d”

CONS: Storage size is restrict based on the Memory(RAM).

Save WATER!!! Every drop in the ocean counts !!!



Leave a Reply