Chat with us, powered by LiveChat

This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

How to Install Magento Redis as Backend Cache

August 13, 2019

5 Min Read
Reading Time: 5 minutes

Warning! This requires some technical changes in your Magento app. Therefore, we recommend that developers should apply this method to a staging/development environment first.

Online store owners, merchants, and developers always strive to improve the Magento store’s performance and responsiveness using different optimization techniques.

Magento supports many backend caches where APC, Full Page Cache, and Varnish Cache are commonly used. If you want to have an exceptionally versatile datastore shared by different procedures, numerous applications, or various server configurations, then installing Magento Redis Cache is the best decision you will take.

Redis cache is becoming a popular and robust caching system for use with Magento and other web applications. This is why it is essential that developers should know how to configure Magento Redis cache through backend without any hiccups.

What is Redis Cache?

Redis cache lets you impart cross-stage, cross-server, or cross-application and makes it an excellent choice for numerous use cases. Its speed, likewise, makes it incredible as a cache layer.

Redis has virtual memory, where once in a while utilized keys would be swapped out to circle so that only the keys needed to fit into the memory are used. Furthermore, the use cases for Redis are those where it’s feasible for the complete information set to fit into the memory.

The essential point of interest in utilizing Redis cache is that store labels are upheld. The moderate-level file system cache is no longer needed to be utilized. Magento Redis cache backend is prescribed in multi-server situations where you have more than one web server.

Why is Redis better?

Redis is a high-speed backend cache with full cache tag support. There is no need for low-level file system cache, and on high traffic Magento stores, the performance is excellent and stable. It is also highly recommended in multi-server environments.

Advantages

If you are using Magento 2 Redis, you get the following advantages:

  • Decreases the memory usage with the backend support of tag-based cache cleanup without any foreach loops.
  • The Magento Redis backend works by indexing tags in files so that tag operations do not require a full scan of every cache file.
  • The metadata and the cache record are stored in the same file rather than separate files resulting in fewer file stat, read, write, lock, and unlink operations.
  • Redis supports on-disk save and master/slave replication.

Scale Your Magento 2 Store With Ease

One-Click Magento installation with your own managed hosting solution.

Magento Redis Requirements

Following are the prerequisites to configure Magento Redis Cache on hosting server:

  • Redis Server
  • PHP Redis Extension

The latest versions are always preferable.

Magento Redis Quick Start

Cloudways servers are based on Redis Cloud Hosting, which provides unbeatable performance. If you are a Cloudways user, you only have to activate Redis, or if you have your hosting server, you need to install Redis and PHP Redis Extension on your server.

Activate Redis Cache on Cloudways

Login to your Cloudways account. If you’re not a Cloudways customer, signup right now and boost your Magento speed 3x times.

Click on your Server.

Under Server Management, tap Settings & Packages.

Click PACKAGES tab.

You’ll see the Redis option, click the INSTALL button to install Redis.

After that, the waiting screen will appear where Redis is being installed and activated on your server.

Once it’s done, go to Manage Services and verify that Redis status shows green signal, it means Redis has been successfully installed and activated on your server.

Magento 2 Redis Configuration

Now, we will configure Magento Redis for version 2.x. You are required to add a Redis configuration script in the env.php file that can be found in Magento2_ROOT/app/etc directory.

In the env.php file, there are different settings and configurations, defined in a PHP array. We will add the following code at the end right before ); which is the ending parenthesis of PHP array.

'cache' =>
  array (
    'frontend' =>
    array (
      'default' =>
      array (
        'backend' => 'Cm_Cache_Backend_Redis',
        'backend_options' =>
        array (
          'server' => '127.0.0.1',
          'port' => '6379',
          'persistent' => '',
          'database' => '0',
          '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',
        ),
      ),
      'page_cache' =>
      array (
        'backend' => 'Cm_Cache_Backend_Redis',
        'backend_options' =>
        array (
          'server' => '127.0.0.1',
          'port' => '6379',
          'persistent' => '',
          'database' => '1',
          'force_standalone' => '0',
          'connect_retries' => '1',
          'read_timeout' => '10',
          'automatic_cleaning_factor' => '0',
          'compress_data' => '0',
          'compress_tags' => '1',
          'compress_threshold' => '20480',
          'compression_lib' => 'gzip',
        ),
      ),
    ),
  ),

Save the env.php file and clear Magento 2 cache with php bin/magento cache:flush command.

Magento 1 Redis Configuration

In this step, you need to edit a couple of files. In Magento 1.x, there is a built-in Redis module that can be found in Magento1_ROOT/app/etc/modules/Cm_RedisSession.xml.

Open Cm_RedisSession.xml in a text editor, you will find the following code.

<config>
 <modules>
   <Cm_RedisSession>
      <active>false</active>
      <codePool>community</codePool>
   </Cm_RedisSession>
 </modules>
</config>

Change the value of <active> to true.

Next, you must copy and place the following code in Magento1_ROOT/app/etc/local.xml file. Open your local.xml in a text editor, under <global> tag, paste this code.

<cache>
 <backend>Cm_Cache_Backend_Redis</backend>
 <backend_options>
   <server>127.0.0.1</server>
   <port>6379</port>
   <persistent></persistent>
   <password></password>
   <force_standalone>0</force_standalone>
   <connect_retries>1</connect_retries>
   <read_timeout>10</read_timeout>
   <automatic_cleaning_factor>0</automatic_cleaning_factor>
   <compress_data>1</compress_data>
   <compress_tags>1</compress_tags>
   <compress_threshold>20480</compress_threshold>
   <compression_lib>gzip</compression_lib>
   <use_lua>0</use_lua>
 </backend_options>
</cache>

Once it’s done, save your local.xml file. Then navigate to Magento1_ROOT/var/cache and delete all files and folders to clear the Magento cache.

Monitor and Verify Magento Redis Cache

To verify whether you have correctly configured Redis cache on Magento, you can use the following commands in the SSH terminal:

  • Type redis-cli monitor and refresh your site, you will see an output on your screen.
  • Type redis-cli ping and you’ll get a reply PONG which means everything is looking good.
  • Type php -m | grep redis by which you’ll see redis in reply, which confirms that the PHP Redis Extension is ready to go.

Also, if you need to clear Redis cache, simply type redis-cli FLUSHALL and an OK reply will confirm that your cache has been cleared successfully.

Final Thoughts

Enabling Magento Redis Cache on your store’s backend will make your Magento store swifter. This is why Magento developers must know how to setup Redis cache in Magento backend.

The optimization formula of Cloudways uses Nginx, Apache, and now, Redis. This unique combination significantly improves the performance of your web applications. Sign up now for a free trial of Cloudways and experience the fastest performance of your Magento store.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Boost Your Magento Store Performance by 5x Times & Maximize Your Sales

Our fastest Magento hosting can help you in growing your business revenue by 500%

Fayyaz Khattak

Fayyaz is a Magento Community Manager at Cloudways - A Managed Magento Hosting Platform. His objective is to learn & share about PHP & Magento Development in Community. Fayyaz is a food lover and enjoys driving. You can email him at m.fayyaz@cloudways.com

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!