Skip to main content
4 of 4
added an explicit question
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

How do I set up a site to use Redis as cache handler?

I'm trying to enable Redis on my Drupal site but when I check the status of the module I keep getting this warning message.

No Redis client connected, this module is useless thereof. Ensure that you enabled module using it or disable it.

The steps I followed to enable Redis are the following.

  1. I edited the config.yml file to add the following lines

    installed_extras:
      - redis
      - php-redis
    
  2. I enabled the Redis module

  3. I edited the settings.php file to add the following lines

    $settings['cache']['default'] = 'cache.backend.redis';
    $settings['redis.connection']['interface'] = 'PhpRedis';
    $settings['container_yamls'][] = 'modules/redis/example.services.yml';
    $settings['container_yamls'][] = 'modules/redis/redis.services.yml';
    

I also tried to execute the following code in index.php and the cache appears to be working.

$redis = new Redis();
$redis->connect('127.0.0.1');
$cache = $redis->get('key');
if ($cache === false) {
  echo "miss";
  $cache = "test";
  $redis->set('key',$cache);
}
else {
  echo "didn't miss";
}
// At this point $cache is either the retrieved cache or a fresh copy, so echo it.
echo $cache;
exit();

It appears that Redis is working but for some reason it isn't used by Drupal.

How do I set up Drupal to use Redis as cache handler?