How to implement Redis in Drupal 7?

HINT: If you have a CMS hosting account (WordPress Performance, Magento Business, Joomla Express, Drupal Express, etc.), $$BrandName$$ will automatically choose the best caching method for you and configure it. You do not need to go through this procedure.

ATTENTION: This tutorial can NOT be combined with an implementation of Memcached in Drupal 7

To implement Redis as easily as possible in Drupal 7, proceed as follows:

  1. First make sure you Activate Redis caching from the control panel
  2. Login in the backend. This can be done by generating a single sign-on link via drush.
    drush uli -l ninefortwo.be
    

    You type this in the root directory of the Drupal installation. Here you get a link that looks approximately like this:

    https://ninefortwo.be/user/reset/1/1456307446/R022fU2OH1QEopq7PsxBXKzgk92Op0kfV_yKIXeY1EU/login
    

    Please note that this link is valid only once. If you logged out, you will have to generate a new link.

  3. Install the “Redis” module
    1. Once logged in, go to “Modules” => “Install new module”.
    2. Go to https://www.drupal.org/project/redis and please copy the link of the zip file of the latest release of Drupal 7.
    3. Then go back and paste this URL into the text field “Install from a URL” and click “Install”
  4. Activate the module
    1. Click “Modules” in the backend of Drupal. Now search for “Redis” from the list of modules.
    2. Now switch on the “Redis” module and click “Save settings” (button on the left bottom)
  5. Adjusting the configuration of the Redis module
    1. Change to the sites/default/ directory.
    2. Add the following to the bottom of the file settings.php:
      /* Redis config
       * Please leave the settings below untouched
       */
        $conf['cache_backends'][]            = 'sites/all/modules/redis/redis.autoload.inc';
        $conf['cache_class_cache']           = 'Redis_Cache';
        $conf['cache_class_cache_menu']      = 'Redis_Cache';
        $conf['cache_class_cache_bootstrap'] = 'Redis_Cache';
        $conf['lock_inc'] = 'sites/all/modules/redis/redis.lock.inc';
        $conf['path_inc'] = 'sites/all/modules/redis/redis.path.inc';
        $conf['redis_client_host'] = ‘250.250.250.1';
        $conf['redis_client_port'] = 10000;
        $conf['redis_client_password'] = "XD23SggF";
      

    Here you need to replace the IP address, port and password, of course, by the Redis IP, port number and password.

Checking Redis

Then check if the Redis Cache is being correctly filled. This is done as follows via the Redis-CLI:

Execute this command:

    redis-cli -h redisipadress -p redisportnumber

Example:

    redis-cli -h 250.250.250.1 -p 10000

This is what will appear

    250.250.250.1:10000>

Now enter the word “AUTH” followed by the password of the Redis instance and press enter. This looks like this:

    250.250.250.1:10000> AUTH ***************

You should now get an “OK” back. Respond with executing this command: “keys *” like so:

    250.250.250.1:10000> keys *

If Redis is configured properly, you see an output similar to the following:

1) "zc:k:f01_B95179D8427D4CD3A6E015530E9E4"
2) "zc:ti:f01_BLOCK_SLIDE2"
3) "zc:k:f01_Zend_LocaleC_nl_NL_country_MR"
4) "zc:ti:f01_BLOCK_CATEGORY_ABOVE_EMPTY_COLLECTION"
5) "zc:k:f01_A9B2A0BB16F05FAA2371C0A5FB79E"
6) "zc:k:f01_CMS_BLOCK_BLOCK_LEFT_TOP_1_1"
7) "zc:k:f01_Zend_LocaleC_sv_SE_language_sv"

 

Updated on 7 February 2023

Was this article helpful?

Related Articles

Comments

Comments are closed.