How to Configure Redis Cache in Magento 2?

The bounce rate on your e-commerce site increases with every second a page takes to load. If you are having this kind of trouble with Magento 2, it might be time to use Redis to get a little more speed. Would you know how to start using it to harness the power of Redis for your own needs?

Below, we dive deep into how to configure Magento 2 Redis, boosting your site's ability to serve up data. So, let's delve in.

Magento 2 Redis Setup and Installation

Use your server's package manager to unpack and install Redis Magento 2 as a setup package. After this, launch and test the service to ensure it runs as it should.

After you are sure Redis can run, you can either edit the "env.php" file to add the Magento 2 Redis configuration settings or run a command to do it.

You should note that if you are using Magento Cloud, it may already come with a Magento Cloud Redis installed. Refer to your documentation for more information on how to set this up.

Magento 2 Redis Session Configuration

The first step you need to take is to extend your app/etc/env.php file and then flush your cache. This involves running a command as follows:

$ cd /data/web/magento2
$ bin/magento setup:config:set
--session-save=redis
--session-save-redis-host=redismaster
--session-save-redis-db=3

You can find all configs and their purpose here.

This will instruct Magento to save session data in Redis instead of the server's usual file system.

If you edit the env.php settings manually, a comprehensive list of settings you may want to investigate includes:

  • host
  • port
  • password
  • timeout
  • persistent_identifier
  • database
  • compression_threshold
  • compression_library
  • log_level
  • max_concurrency
  • break_after_frontend
  • break_after_adminhtml
  • first_lifetime
  • bot_first_lifetime
  • bot_lifetime
  • disable_locking
  • min_lifetime
  • max_lifetime

                                    You will then want to flush your cache by running the following command:

                                    $ rm -rf /data/web/magento2/var/cache/*
                                    $ redis-cli flushall

                                    Magento 2 Redis Full Page Cache Configuration

                                    You may instead want to enable page caching in your Magento Redis Configuration. If so, refer to the official Adobe Commerce documentation.

                                    Then, after setting up a Magento 2 Redis cache, you will need to flush the existing cache as above. You may also want to flush the database by entering the following command:

                                    $ redis-cli -n 1 flushdb

                                    Or flush everything including the Magento Redis cache with the following:

                                    $ redis-cli flushall

                                    What Else Can Magento 2 Redis Do for You?

                                    Boosting your site's performance with Magento 2 Redis is imperative to ensure you stay ahead of the competition. As you can see above, configuring Magento 2.4 Redis can make a world of difference.

                                    Here at Amasty, we can help to simplify the configuration process and get you started faster. If you are ready to improve your store's UX, we can make it happen. So, check out our solutions today to get started.

                                    How can we help you?

                                    Didn’t you find the answer to your question? We are always happy to help you out.