简体   繁体   English

Drupal Redis模块无法连接到PHP-Redis

[英]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: 我试图在我的Drupal网站上启用Redis ,但是当我检查模块的状态时,我不断收到以下警告消息:

No Redis client connected, this module is useless thereof. 未连接Redis客户端,此模块无用。 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 . 我正在使用Drupal-vm在虚拟机上运行的Drupal 8网站上工作。

The steps I followed to enable Redis: 我启用Redis的步骤如下:

  1. Edited the Drupal-vm config.yml 编辑了Drupal-vm config.yml

    installed_extras: installed_extras:

    • redis Redis的
    • php-redis PHP-的Redis

  1. Enabled the Redis module in Drupal 在Drupal中启用Redis模块

  1. Edited settings.php 编辑settings.php

$settings['cache']['default'] = 'cache.backend.redis'; $ settings ['cache'] ['default'] ='cache.backend.redis';

$settings['redis.connection']['interface'] = 'PhpRedis'; $ settings ['redis.connection'] ['interface'] ='PhpRedis';

$settings['container_yamls'][] = 'modules/redis/example.services.yml'; $ settings ['container_yamls'] [] ='modules / redis / example.services.yml';

$settings['container_yamls'][] = 'modules/redis/redis.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: 我还尝试在index.php中执行以下代码,并且缓存似乎正在工作:

$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. 因此看来Redis可以正常工作,但是由于某种原因,Drupal并未使用它。

Install Redis. 安装Redis。 Redis can be configured on the same box as your web server or on its own. 可以将Redis与Web服务器配置在同一框中,也可以单独配置。 To install Redis on Ubuntu run the following commands: 要在Ubuntu上安装Redis,请运行以下命令:

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。 Redis is ready to run and is configured to persist data out of the box. Redis已准备就绪,可以运行并且已配置为持久保存数据。

Install the PhpRedis library. 安装PhpRedis库。 Download and install the Redis Drupal module. 下载并安装Redis Drupal模块。 You do not need to enable this module. 您不需要启用此模块。 Configure your Drupal site to use Redis for caching instead of the Drupal cache database tables. 将您的Drupal站点配置为使用Redis而不是Drupal缓存数据库表进行缓存。 In settings.php or settings.local.php add: 在settings.php或settings.local.php中添加:

/**
 * 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';
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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