【问题标题】:Drupal Redis module doesn't connect to PHP-RedisDrupal Redis 模块未连接到 PHP-Redis
【发布时间】:2018-12-05 10:23:13
【问题描述】:

我正在尝试在我的 Drupal 网站上启用 Redis,但是当我检查模块的状态时,我不断收到以下警告消息:

没有连接Redis客户端,这个模块没用。确保这件事 您使用它启用模块或禁用它。

我正在使用 Drupal-vm 在虚拟机上运行 Drupal 8 网站。

我启用 Redis 的步骤:

  1. 编辑了 Drupal-vm config.yml

    已安装的附加功能:

    • redis
    • php-redis

  1. 在 Drupal 中启用 Redis 模块

  1. 已编辑 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';


我还尝试在 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();

因此,Redis 似乎正在运行,但由于某种原因,Drupal 并未使用它。

【问题讨论】:

    标签: php drupal redis drupal-8 phpredis


    【解决方案1】:

    安装 Redis。 Redis 可以与您的 Web 服务器在同一个机器上配置,也可以单独配置。要在 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
    

    配置 Redis。 Redis 已准备好运行,并且已配置为开箱即用地持久化数据。

    安装 PhpRedis 库。下载并安装 Redis Drupal 模块。您不需要启用此模块。 将您的 Drupal 站点配置为使用 Redis 进行缓存,而不是使用 Drupal 缓存数据库表。在 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';
    }
    

    【讨论】:

    • 您好,感谢您的回答,但正如我提到的,redis 已安装并正在工作,而您发布的配置值与我在问题中列出的相同。您的答案中唯一的额外价值是 $conf['cache_class_cache'] = 'Redis_Cache';我已经尝试过但没有结果(我已经用谷歌搜索了这个问题一整天并测试了我可以复制/粘贴的所有可能配置,包括你的:()。
    • 我当然也在 drupal.org 上问过 ;) 但那里还没有答案。
    • 你能把你贴的链接给我吗?
    猜你喜欢
    • 1970-01-01
    • 2021-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多