我正在尝试在我的 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 的步骤:
编辑了 Drupal-vm config.yml
installed_extras:
- redis
- php-redis
- 在 Drupal 中启用 Redis 模块
- 编辑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/