Skip to content

Commit

Permalink
MDL-65941 cache: Prevent cache config failure on redis problems.
Browse files Browse the repository at this point in the history
  • Loading branch information
micaherne authored and snake committed Nov 11, 2020
1 parent d330035 commit 2385ae7
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions cache/stores/redis/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,22 +182,28 @@ protected function new_redis($server, $prefix = '', $password = '') {
$server = $serverconf[0];
$port = $serverconf[1];
}
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);

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;
}
// Database setting option...
$this->isready = $this->ping($redis);
} else {
} catch (\RedisException $e) {
$this->isready = false;
}

return $redis;
}

Expand Down

0 comments on commit 2385ae7

Please sign in to comment.