How to configure Drupal to use Redis

This article describes how to configure Drupal 9 to use Redis.

Redis is an open-source memory object caching system that websites can use to help accelerate page load times. Redis works by caching in RAM frequently accessed data, such as the results of API calls, database calls, and more.

  • Redis is currently enabled on Turbo shared, Turbo reseller, Managed VPS, and Managed Dedicated server accounts.
  • If you have an unmanaged VPS, you have full root access and can install and configure Redis yourself.
  • Redis is not supported on non-Turbo shared hosting accounts at this time.

Installing the dependencies and module

First, you must install some dependencies and a module so Drupal can access and use Redis. To do this, follow these steps:

  1. Log in to your account using SSH.
  2. At the command prompt, change to the directory where you installed Drupal.
  3. Type the following commands:
    composer require predis/predis
    composer require drupal/redis
    cp modules/contrib/redis/example.services.yml sites/default/redis.services.yml
    
  4. Log in to your Drupal site as the administrator.
  5. On the top menu bar, click Extend.
  6. On the List tab, under PERFORMANCE, select the check box next to Redis.
  7. Click Install. You receive a Module Redis has been enabled message.

Configuring Drupal settings

After you install and enable the Redis module, you are ready to configure Drupal to actually use Redis. To do this, follow these steps:

  1. In the directory where you installed Drupal, use your preferred text editor to open the sites/default/settings.php file.
  2. Configure the Redis connection settings:
    • If you have a Managed VPS or Dedicated Server, copy the following text and append it to the settings.php file:
      $settings['redis.connection']['interface'] = 'Predis';
      $settings['redis.connection']['host'] = 'localhost';
      $settings['redis.connection']['port'] = '6379';
      $settings['cache']['default'] = 'cache.backend.redis';
      $settings['container_yamls'][] = 'sites/default/redis.services.yml';
      
    • If you have a Turbo shared or reseller account, copy the following text and append it to the settings.php file. Replace username with your account username:

      $settings['redis.connection']['interface'] = 'Predis';
      $settings['redis.connection']['host'] = '/home/username/.redis/redis.sock';
      $settings['redis.connection']['port'] = NULL;
      $settings['cache']['default'] = 'cache.backend.redis';
      $settings['container_yamls'][] = 'sites/default/redis.services.yml';
      
    For additional information about these options, see the modules/contrib/redis/README.md file.
  3. Save your changes to the settings.php file. Redis is now configured for Drupal.

    To verify that Drupal is working correctly with Redis, on the top menu bar of the administration interface, click Reports, and then click Redis. You should see a Connected, using the Predis client message, along with statistics about the Redis cache and connection. If you see a Not connected message, then Redis is not integrated with Drupal.

More Information

For more information about Redis, please visit https://redis.io.

Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.

We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.