From 03c6edd265b03f3773ebf60af9ddd81a5261c71a Mon Sep 17 00:00:00 2001 From: vibbow Date: Wed, 13 Feb 2019 16:54:34 +0800 Subject: [PATCH 1/2] Update Cache RedisHandler to support select database. --- app/Config/Cache.php | 1 + system/Cache/Handlers/RedisHandler.php | 6 ++++++ user_guide_src/source/libraries/caching.rst | 1 + 3 files changed, 8 insertions(+) diff --git a/app/Config/Cache.php b/app/Config/Cache.php index 15038399a43e..015bd6fd68c4 100644 --- a/app/Config/Cache.php +++ b/app/Config/Cache.php @@ -97,6 +97,7 @@ class Cache extends BaseConfig 'password' => null, 'port' => 6379, 'timeout' => 0, + 'database' => 0, ]; /* diff --git a/system/Cache/Handlers/RedisHandler.php b/system/Cache/Handlers/RedisHandler.php index 57792e7a9af4..5dbdb5dc9529 100644 --- a/system/Cache/Handlers/RedisHandler.php +++ b/system/Cache/Handlers/RedisHandler.php @@ -60,6 +60,7 @@ class RedisHandler implements CacheInterface 'password' => null, 'port' => 6379, 'timeout' => 0, + 'database' => 0, ]; /** @@ -118,6 +119,11 @@ public function initialize() { // log_message('error', 'Cache: Redis authentication failed.'); } + + if (isset($config['database']) && ! $this->redis->select($config['database'])) + { + // log_message('error', 'Cache: Redis select database failed.'); + } } catch (\RedisException $e) { diff --git a/user_guide_src/source/libraries/caching.rst b/user_guide_src/source/libraries/caching.rst index 28765401ce47..1ebbcd0374b0 100644 --- a/user_guide_src/source/libraries/caching.rst +++ b/user_guide_src/source/libraries/caching.rst @@ -246,6 +246,7 @@ Available options are:: $config['password'] = NULL; $config['port'] = 6379; $config['timeout'] = 0; + $config['database'] = 0; For more information on Redis, please see `http://redis.io `_. From 8b2bd4cec9870fb610f2d59ab192ef94c4413fc7 Mon Sep 17 00:00:00 2001 From: vibbow Date: Thu, 14 Feb 2019 12:17:41 +0800 Subject: [PATCH 2/2] Log an error if redis select database failed. --- system/Cache/Handlers/RedisHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Cache/Handlers/RedisHandler.php b/system/Cache/Handlers/RedisHandler.php index 5dbdb5dc9529..793edb761fd4 100644 --- a/system/Cache/Handlers/RedisHandler.php +++ b/system/Cache/Handlers/RedisHandler.php @@ -122,7 +122,7 @@ public function initialize() if (isset($config['database']) && ! $this->redis->select($config['database'])) { - // log_message('error', 'Cache: Redis select database failed.'); + log_message('error', 'Cache: Redis select database failed.'); } } catch (\RedisException $e)