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.

This holiday season, maximize your sales through enhanced website performance and 24/7 caring support. SAVE 30% NOW

Install Redis Cache on Magento 2 With Step By Step Guide

Updated on  22nd February

4 Min Read
Reading Time: 4 minutes

Store Owners, Merchants as well as Developers are now adopting Magento 2 because of its new design, the increase in security & performance, memory optimization, and support with latest technology trends. But still everyone is looking and trying to improve the Magento site’s performance and responsiveness using different optimization techniques.

Magento 2 Redis Cache

Most of the developers always go through different approaches like enabling default cache and compilation of Magento 2, but, unfortunately, utilizing the file-system based cache for a Magento site simply makes your site run a bit faster instead of giving it a boost.

So the question raised is that, what would you use? A file-system based cache or any other option by which you’ll be able to work and load your site faster? What if you develop your Magento store with a faster backend cache?

Sounds interesting, right?

Same as our previous article How To Setup Redis Cache On Magento Backend, let’s talk about Redis Cache and its configuration on Magento 2.

Why is Redis better?

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

Cloudways Magento Hosting For Developers

Advantages

The following are further advantages of Redis with Magento 2:

  • Decreases the memory usage with the backend support of tag-based cache cleanup without any foreach loops.
  • The 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.

Requirements

The following are the prerequisites to configure Redis Cache on Magento 2:

  • Redis Server
  • PHP Redis Extension

The latest versions are always preferable.

Installation

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 own web server, you need to install Redis and PHP Redis Extension on your server.

Activate Redis on Cloudways

Login to your Cloudways account. Click on your Server. Under “Server Management”, click “Settings & Packages” and click “PACKAGES” tab. You’ll see the Redis option, click “INSTALL” button. After that, you’ll see a waiting screen for the server where Redis is being activated.

After Redis activation, Go to “Manage Services” and verify that Redis status shows green signal, its mean Redis has been successfully activated on your server.

For more information, see this article Activate Redis On Your Cloud Server Now.

Configure Redis Cache

In this step, we are going to configure Redis on Magento 2. You need to add Redis configuration in Magento2_ROOT_Directory > app > etc > env.php file. In this env.php file, you would find a large PHP array with different settings and configuration. We would add the following configuration at the end of this file right before “);” which is the ending parenthesis of PHP array:

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

Monitor & Verify Redis Cache

To verify whether you have correctly configured Redis cache on Magento 2, 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 of ‘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, simple type redis-cli FLUSHALL and an OK reply will confirm that your cache has been cleared successfully.

Share your opinion in the comment section. COMMENT NOW

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

Start Growing with Cloudways Today.

Our Clients Love us because we never compromise on these

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

THERE’S MORE TO READ.