php - Drupal Redis 模块没有连接到 PHP-Redis

标签 php drupal redis drupal-8 phpredis

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

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

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

启用 Redis 的步骤:

  1. 编辑了 Drupal-vm config.yml

    installed_extras:

    • 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 未使用它。

最佳答案

安装 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';
}

关于php - Drupal Redis 模块没有连接到 PHP-Redis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53630058/

相关文章:

PHP JSON GET 在网页上正确显示,但在 php 中不正确

php - 将信息动态加载到 Twitter Bootstrap 模态

php - 使用 PHP 和 ImageMagick 将 PDF 转换为 JPEG

drupal - 刷新现有节点以获取 Drupal 中的自动节点标题

php - 使用实体字段查询搜索多个字段的最佳方式?

python - Redis 与 Twemproxy 对比 memcached

php - CakePHP,表$belongsTo 两个表:错误Error: Cannot redeclare table::$belongsTo

php - 在 DRUPAL 6 中如何使节点链接直接指向其文件内容?

node.js - 使用 node-redis 将 AWS redis 连接到 Node

hash - 在 Redis 中交叉巨大的 HyperLogLogs 的最佳方法