Magento Tutorials

How to use Redis for Magento default cache

magento-redis

The development of web design at the speed of light has been raising customers expectation of near real-time interactions with low latency when browsing a particular page. Therefore the need of putting in-memory data stores in order to archive the high demand for real-time and constraints of computer architectures.

That’s the reason why you should definitely use Redis in Magento – a low-latency, persistent and widely used storage.

Use Redis for Magento default cache

Intelligent caching and Reliable persistence

Redis is a popular open source database management system which is proven to be faster than other members of NoSQL databases family and also known as a system of record rather than a volatile cache. Largely used by many companies (you can count Yahoo!, Twitter, Flickr… as its customers), Redis is included in every package for developers. It is actually very common to find a web stack with built-in support for Redis.

Despite the fact that it’s an in-memory data store, Redis can, in fact, persist data to disk to ensure data’s durability following a server shutdown.  Unlike others in which data will be lost in the event of a sudden power loss, Redis is capable of recovering its state and performs very well when compared to disk-centric databases. For this highly requested feature that you cannot find in other data management solutions, Redis solves the very problem of failure in data replication and provides a high availability.

However, the main reason for its popularity is in its relatively simple set up for developers. Let’s take a couple of minutes to set up Redis in Magento so you can experience an immediate and considerable impact on performance.

How to use Redis in Magento default cache

Step 1:  Install Redis to get started.

Step 2:  Set up Redis in Magento

Run the setup:config:set command and

 bin/magento setup:config:set --cache-backend=redis --cache-backend-redis-<parameter_name>=<parameter_value>...

where:

--cache-backend=redis enables Redis default caching. If this feature has already been enabled, omit this parameter.

--cache-backend-redis-<parameter_name>=<parameter_value> is a list of parameter/value pairs that configure default caching.

Step 3:  Set up Magento for Redis

Add a configuration similar to the following to <your Magento install dir>app/etc/env.php:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
'cache' =>
array(
'frontend' =>
array(
'default' =>
array(
'backend' => 'Cm_Cache_Backend_Redis',
'backend_options' =>
array(
'server' => '127.0.0.1',
'database' => '0',
'port' => '6379'
),
),
'page_cache' =>
array(
'backend' => 'Cm_Cache_Backend_Redis',
'backend_options' =>
array(
'server' => '127.0.0.1',
'port' => '6379',
'database' => '1',
'compress_data' => '0'
)
)
)
),

Step 4:  Verification

To verify that Redis in Magento is working fine, use this command:
redis-cli monitor
If you use Redis for page caching, you’ll see output similar to the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1476826133.810090 [0 127.0.0.1:52366] "select" "1"
1476826133.816293 [0 127.0.0.1:52367] "select" "0"
1476826133.817461 [0 127.0.0.1:52367] "hget" "zc:k:ea6_GLOBAL__DICONFIG" "d"
1476826133.829666 [0 127.0.0.1:52367] "hget" "zc:k:ea6_DICONFIG049005964B465901F774DB9751971818" "d"
1476826133.837854 [0 127.0.0.1:52367] "hget" "zc:k:ea6_INTERCEPTION" "d"
1476826133.868374 [0 127.0.0.1:52368] "select" "1"
1476826133.869011 [0 127.0.0.1:52369] "select" "0"
1476826133.869601 [0 127.0.0.1:52369] "hget" "zc:k:ea6_DEFAULT_CONFIG_CACHE_DEFAULT__10__235__32__1080MAGENTO2" "d"
1476826133.872317 [0 127.0.0.1:52369] "hget" "zc:k:ea6_INITIAL_CONFIG" "d"
1476826133.879267 [0 127.0.0.1:52369] "hget" "zc:k:ea6_GLOBAL_PRIMARY_PLUGIN_LIST" "d"
1476826133.883312 [0 127.0.0.1:52369] "hget" "zc:k:ea6_GLOBAL__EVENT_CONFIG_CACHE" "d"
1476826133.898431 [0 127.0.0.1:52369] "hget" "zc:k:ea6_DB_PDO_MYSQL_DDL_STAGING_UPDATE_1" "d"
1476826133.898794 [0 127.0.0.1:52369] "hget" "zc:k:ea6_RESOLVED_STORES_D1BEFA03C79CA0B84ECC488DEA96BC68" "d"
1476826133.905738 [0 127.0.0.1:52369] "hget" "zc:k:ea6_DEFAULT_CONFIG_CACHE_STORE_DEFAULT_10__235__32__1080MAGENTO2" "d"

... more ...

1476826210.634998 [0 127.0.0.1:52439] "hmset" "zc:k:ea6_MVIEW_CONFIG" "d" "a:18:{s:19:"design_config_dummy";a:4:{s:7:"view_id";s:19:"design_config_dummy";s:12:"action_class";s:39:"Magento\\Theme\\Model\\Indexer\\Mview\\Dummy";s:5:"group";s:7:"indexer";s:13:"subscriptions";a:0:{}}s:14:"customer_dummy";a:4:{s:7:"view_id";s:14:"customer_dummy";s:12:"action_class";s:42:"Magento\\Customer\\Model\\Indexer\\Mview\\Dummy";s:5:"group";s:7:"indexer";s:13:"subscriptions";a:0:{}}s:13:"cms_page_grid";a:4:{s:7:"view_id";s:13:"cms_page_grid";s:12:"action_class";s:43:"Magento\\Catalog\\Model\\Indexer\\Category\\Flat";s:5:"group";s:7:"indexer";s:13:"subscriptions";a:1:{s:8:"cms_page";a:3:{s:4:"name";s:8:"cms_page";s:6:"column";s:7:"page_id";s:18:"subscription_model";N;}}}s:21:"catalog_category_flat";a:4:{s:7:"view_id";s:21:"catalog_category_flat";s:12:"action_class";s:43:"Magento\\Catalog\\Model\\Indexer\\Category\\Flat";s:5:"group";s:7:"indexer";s:13:"subscriptions";a:6:{s:23:"catalog_category_entity";a:3:{s:4:"name";s:23:"catalog_category_entity";s:6:"column";s:9:"entity_id";s:18:"subscription_model";N;}s:31:"catalog_category_entity_decimal";a:3:{s:4:"name";s:31:"catalog_category_entity_decimal";s:6:"column";s:9:"entity_id";s:18:"subscription_model";s:71:"Magento\\CatalogStaging\\Model\\Mview\\View\\Category\\Attribute\\Subscription";}s:27:"catalog_category_entity_int";a:3:{s:4:"name";s:27:"catalog_category_entity_int";s:6:"column";s:9:"entity_id";s:18:"subscription_model";s:71:"Magento\\CatalogStaging\\Model\\Mview\\View\\Category\\Attribute\\Subscription";}s:28:"catalog_category_entity_text";a:3:{s:4:"name";s:28:"catalog_category_entity_text";s:6:"column";s:9:"entity_id";s:18:"subscription_model";s:71:"Magento\\CatalogStaging\\Model\\Mview\\View\\Category\\Attribute\\Subscription";}s:31:"catalog_category_entity_varchar";a:3:{s:4:"name";s:31:"catalog_category_entity_varchar";s:6:"column";s:9:"entity_id";s:18:"subscription_model";s:71:"Magento\\CatalogStaging\\Model\\Mview\\View\\Category\\Attribute\\Subscription";}s:32:"catalog_category_entity_datetime";a:3:{s:4:"name";s:32:"catalog_category_entity_datetime";s:6:"column";s:9:"entity_id";s:18:"subscription_model";s:71:"Magento\\CatalogStaging\\Model\\Mview\\View\\Category\\Attribute\\Subscription";}}}s:24:"catalog_category_product";a:4:{s:7:"view_id";s:24:"catalog_category_product";s:12:"action_class";s:46:"Magento\\Catalog\\Model\\Indexer\\Category\\Product";s:5:"group";s:7:"indexer";s:13:"subscriptions";a:2:{s:23:"catalog_category_entity";a:3:{s:4:"name";s:23:"catalog_category_entity";s:6:"column"

... more ...
1 Comments

Thuy

    avatar
    1 Comment threads
    0 Thread replies
    0 Followers
     
    Most reacted comment
    Hottest comment thread
    1 Comment authors
    Ashwin Parkar Recent comment authors
      Subscribe  
    newest oldest most voted
    Notify of
    Ashwin Parkar
    Guest

    Perfect article, Thanks for sharing.