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


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





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’ => ‘’,

‘database’ => ‘0’,

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

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

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

‘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

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s