简体   繁体   中英

Drupal Redis module doesn't connect to PHP-Redis

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.

I'm working on a Drupal 8 website running on a virtual machine with Drupal-vm .

The steps I followed to enable Redis:

  1. Edited the Drupal-vm config.yml

    installed_extras:

    • redis
    • php-redis

  1. Enabled the Redis module in Drupal

  1. Edited settings.php

$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');
//Cache miss
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();

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

Install Redis. Redis can be configured on the same box as your web server or on its own. To install Redis on Ubuntu run the following commands:

sudo apt-get update && sudo apt-get upgrade

sudo apt-get install software-properties-common

sudo add-apt-repository ppa:chris-lea/redis-server

sudo apt-get update && sudo apt-get upgrade

sudo apt-get install redis-server

Configure Redis. Redis is ready to run and is configured to persist data out of the box.

Install the PhpRedis library. Download and install the Redis Drupal module. You do not need to enable this module. Configure your Drupal site to use Redis for caching instead of the Drupal cache database tables. In settings.php or settings.local.php add:

/**
 * Redis Configuration.
 */
$conf['chq_redis_cache_enabled'] = TRUE;
if (isset($conf['chq_redis_cache_enabled']) && $conf['chq_redis_cache_enabled']) {
  $settings['redis.connection']['interface'] = 'PhpRedis';
  $settings['cache']['default'] = 'cache.backend.redis';
  // Note that unlike memcached, redis persists cache items to disk so we can
  // actually store cache_class_cache_form in the default cache.
  $conf['cache_class_cache'] = 'Redis_Cache';
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM