From e9e4ab00991343ba94f9542c1a6f18a42b559257 Mon Sep 17 00:00:00 2001 From: kemeng Date: Mon, 16 Nov 2015 20:03:24 +0800 Subject: do not try to auth/select db on redis connect failure --- .../Session/drivers/Session_redis_driver.php | 28 +++++++++++++--------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'system') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index 44ffddc4b..8f9bcce24 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -141,31 +141,37 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle return FALSE; } + $connected = TRUE; $redis = new Redis(); if ($this->_config['save_path']['type'] == 'unix') { if ( ! $redis->connect($this->_config['save_path']['path'])) { log_message('error', 'Session: Unable to connect to Redis with the configured settings.'); + $connected = FALSE; } } elseif ( ! $redis->connect($this->_config['save_path']['host'], $this->_config['save_path']['port'], $this->_config['save_path']['timeout'])) { log_message('error', 'Session: Unable to connect to Redis with the configured settings.'); + $connected = FALSE; } - if (isset($this->_config['save_path']['password']) && ! $redis->auth($this->_config['save_path']['password'])) + if ($connected) { - log_message('error', 'Session: Unable to authenticate to Redis instance.'); - } - elseif (isset($this->_config['save_path']['database']) && ! $redis->select($this->_config['save_path']['database'])) - { - log_message('error', 'Session: Unable to select Redis database with index '.$this->_config['save_path']['database']); - } - else - { - $this->_redis = $redis; - return TRUE; + if (isset($this->_config['save_path']['password']) && ! $redis->auth($this->_config['save_path']['password'])) + { + log_message('error', 'Session: Unable to authenticate to Redis instance.'); + } + elseif (isset($this->_config['save_path']['database']) && ! $redis->select($this->_config['save_path']['database'])) + { + log_message('error', 'Session: Unable to select Redis database with index '.$this->_config['save_path']['database']); + } + else + { + $this->_redis = $redis; + return TRUE; + } } return FALSE; -- cgit v1.2.3-24-g4f1b