From c9a9d82bbc966c97876c2b6d5bc94ae3f4b4135f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 5 Jan 2022 22:49:24 +0200 Subject: Fix #5562 --- system/libraries/Cache/drivers/Cache_redis.php | 28 +++++++++++--------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'system') diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php index 9b082d11b..e541237e3 100644 --- a/system/libraries/Cache/drivers/Cache_redis.php +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -95,6 +95,7 @@ class CI_Cache_redis extends CI_Driver * if a Redis connection can't be established. * * @return void + * @throws RedisException * @see Redis::connect() */ public function __construct() @@ -132,26 +133,21 @@ class CI_Cache_redis extends CI_Driver $this->_redis = new Redis(); - try + // The following calls used to be wrapped in a try ... catch + // and just log an error, but that only causes more errors later. + if ( ! $this->_redis->connect($config['host'], ($config['host'][0] === '/' ? 0 : $config['port']), $config['timeout'])) { - if ( ! $this->_redis->connect($config['host'], ($config['host'][0] === '/' ? 0 : $config['port']), $config['timeout'])) - { - log_message('error', 'Cache: Redis connection failed. Check your configuration.'); - } - - if (isset($config['password']) && ! $this->_redis->auth($config['password'])) - { - log_message('error', 'Cache: Redis authentication failed.'); - } + log_message('error', 'Cache: Redis connection failed. Check your configuration.'); + } - if (isset($config['database']) && $config['database'] > 0 && ! $this->_redis->select($config['database'])) - { - log_message('error', 'Cache: Redis select database failed.'); - } + if (isset($config['password']) && ! $this->_redis->auth($config['password'])) + { + log_message('error', 'Cache: Redis authentication failed.'); } - catch (RedisException $e) + + if (isset($config['database']) && $config['database'] > 0 && ! $this->_redis->select($config['database'])) { - log_message('error', 'Cache: Redis connection refused ('.$e->getMessage().')'); + log_message('error', 'Cache: Redis select database failed.'); } } -- cgit v1.2.3-24-g4f1b