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 +++++++++++--------------- user_guide_src/source/changelog.rst | 5 +++++ 2 files changed, 17 insertions(+), 16 deletions(-) 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.'); } } diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 3e858feb3..2a729264e 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -135,6 +135,11 @@ Release Date: Not Released - Added ability to generate ``data:image/png;base64`` URIs instead of writing image files to disk. - Updated to always create PNG images instead of JPEG. +Bug fixes for 3.2.0 +=================== + +- Fixed a bug (#5562) - :doc:`Cache Library ` 'redis' driver would pointlessly attempt to perform its functions if a connection to the Redis server failed. + Version 3.1.12 ============== -- cgit v1.2.3-24-g4f1b