diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2021-07-21 12:18:42 +0200 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2021-07-22 07:42:26 +0200 |
commit | 6e00fe8c26c8d1cd68497911371c3b4b785d903c (patch) | |
tree | f58216f080936a6991e671e022995f80113096e6 /lib/private/RedisFactory.php | |
parent | 66c1e05452e6f5787cb2df054e59428aa417964a (diff) | |
download | nextcloud-server-6e00fe8c26c8d1cd68497911371c3b4b785d903c.tar.gz nextcloud-server-6e00fe8c26c8d1cd68497911371c3b4b785d903c.zip |
Properly support RedisCluster
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'lib/private/RedisFactory.php')
-rw-r--r-- | lib/private/RedisFactory.php | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/lib/private/RedisFactory.php b/lib/private/RedisFactory.php index dbac2b58204..7609a75d52d 100644 --- a/lib/private/RedisFactory.php +++ b/lib/private/RedisFactory.php @@ -46,28 +46,29 @@ class RedisFactory { } private function create() { - $isCluster = !empty($this->config->getValue('redis.cluster', [])); - $config = $this->config->getValue('redis', []); + $isCluster = in_array('redis.cluster', $this->config->getKeys()); + $config = $isCluster + ? $this->config->getValue('redis.cluster', []) + : $this->config->getValue('redis', []); - // Init cluster config if any - if ($isCluster) { - if (!class_exists('RedisCluster')) { - throw new \Exception('Redis Cluster support is not available'); - } - // Replace config with the cluster config - $config = $this->config->getValue('redis.cluster', []); + if (empty($config)) { + throw new \Exception('Redis config is empty'); + } + + if ($isCluster && !class_exists('RedisCluster')) { + throw new \Exception('Redis Cluster support is not available'); } if (isset($config['timeout'])) { $timeout = $config['timeout']; } else { - $timeout = null; + $timeout = 0.0; } if (isset($config['read_timeout'])) { $readTimeout = $config['read_timeout']; } else { - $readTimeout = null; + $readTimeout = 0.0; } $auth = null; @@ -85,10 +86,11 @@ class RedisFactory { // cluster config if ($isCluster) { + // Support for older phpredis versions not supporting connectionParameters if ($connectionParameters !== null) { $this->instance = new \RedisCluster(null, $config['seeds'], $timeout, $readTimeout, false, $auth, $connectionParameters); } else { - $this->instance = new \RedisCluster(null, $config['seeds'], $timeout, $readTimeout, $auth); + $this->instance = new \RedisCluster(null, $config['seeds'], $timeout, $readTimeout, false, $auth); } if (isset($config['failover_mode'])) { @@ -111,13 +113,17 @@ class RedisFactory { $port = null; } - if (!empty($connectionParameters)) { + // Support for older phpredis versions not supporting connectionParameters + if ($connectionParameters !== null) { + // Non-clustered redis requires connection parameters to be wrapped inside `stream` $connectionParameters = [ 'stream' => $this->getSslContext($config) ]; + $this->instance->connect($host, $port, $timeout, null, 0, $readTimeout, $connectionParameters); + } else { + $this->instance->connect($host, $port, $timeout, null, 0, $readTimeout); } - $this->instance->connect($host, $port, $timeout, null, 0, $readTimeout, $connectionParameters); // Auth if configured if ($auth !== null) { @@ -134,7 +140,7 @@ class RedisFactory { * Get the ssl context config * * @param Array $config the current config - * @return Array + * @return Array|null * @throws \UnexpectedValueException */ private function getSslContext($config) { @@ -147,7 +153,7 @@ class RedisFactory { } return $config['ssl_context']; } - return []; + return null; } public function getInstance() { |