From 1a8de51e258cf786134cdb26005757a55ce5c0d7 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Wed, 22 May 2019 12:19:07 +0200 Subject: [PATCH] Allow redis cluster to use password Signed-off-by: Morris Jobke --- config/config.sample.php | 8 ++++++-- lib/private/RedisFactory.php | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/config/config.sample.php b/config/config.sample.php index 201aa9ca9db..380db6a8e9a 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -1165,15 +1165,19 @@ $CONFIG = array( * which then causes a FileLocked exception. * * See https://redis.io/topics/cluster-spec for details about the Redis cluster + * + * Authentication works with phpredis version 4.2.1+. See + * https://github.com/phpredis/phpredis/commit/c5994f2a42b8a348af92d3acb4edff1328ad8ce1 */ 'redis.cluster' => [ 'seeds' => [ // provide some/all of the cluster servers to bootstrap discovery, port required 'localhost:7000', - 'localhost:7001' + 'localhost:7001', ], 'timeout' => 0.0, 'read_timeout' => 0.0, - 'failover_mode' => \RedisCluster::FAILOVER_ERROR + 'failover_mode' => \RedisCluster::FAILOVER_ERROR, + 'password' => '', // Optional, if not defined no password will be used. ], diff --git a/lib/private/RedisFactory.php b/lib/private/RedisFactory.php index 754437c06c7..6e4afe6a949 100644 --- a/lib/private/RedisFactory.php +++ b/lib/private/RedisFactory.php @@ -56,7 +56,11 @@ class RedisFactory { } else { $readTimeout = null; } - $this->instance = new \RedisCluster(null, $config['seeds'], $timeout, $readTimeout); + if (isset($config['password']) && $config['password'] !== '') { + $this->instance = new \RedisCluster(null, $config['seeds'], $timeout, $readTimeout, false, $config['password']); + } else { + $this->instance = new \RedisCluster(null, $config['seeds'], $timeout, $readTimeout); + } if (isset($config['failover_mode'])) { $this->instance->setOption(\RedisCluster::OPT_SLAVE_FAILOVER, $config['failover_mode']); -- 2.39.5