From 2385ae7ee2763b3106e426c2ca3b331ad3dfa378 Mon Sep 17 00:00:00 2001 From: Michael Aherne Date: Mon, 17 Jun 2019 12:24:39 +0100 Subject: [PATCH] MDL-65941 cache: Prevent cache config failure on redis problems. --- cache/stores/redis/lib.php | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/cache/stores/redis/lib.php b/cache/stores/redis/lib.php index bde6b9ecc0a..9a6b0576651 100644 --- a/cache/stores/redis/lib.php +++ b/cache/stores/redis/lib.php @@ -182,22 +182,28 @@ class cachestore_redis extends cache_store implements cache_is_key_aware, cache_ $server = $serverconf[0]; $port = $serverconf[1]; } - if ($redis->connect($server, $port)) { - if (!empty($password)) { - $redis->auth($password); + + try { + if ($redis->connect($server, $port)) { + if (!empty($password)) { + $redis->auth($password); + } + // If using compressor, serialisation will be done at cachestore level, not php-redis. + if ($this->compressor == self::COMPRESSOR_NONE) { + $redis->setOption(Redis::OPT_SERIALIZER, $this->serializer); + } + if (!empty($prefix)) { + $redis->setOption(Redis::OPT_PREFIX, $prefix); + } + // Database setting option... + $this->isready = $this->ping($redis); + } else { + $this->isready = false; } - // If using compressor, serialisation will be done at cachestore level, not php-redis. - if ($this->compressor == self::COMPRESSOR_NONE) { - $redis->setOption(Redis::OPT_SERIALIZER, $this->serializer); - } - if (!empty($prefix)) { - $redis->setOption(Redis::OPT_PREFIX, $prefix); - } - // Database setting option... - $this->isready = $this->ping($redis); - } else { + } catch (\RedisException $e) { $this->isready = false; } + return $redis; }