From 874096c1f652f25b7f3e89e8c6b45b13c8a5e0e8 Mon Sep 17 00:00:00 2001 From: sskaje Date: Sat, 14 Nov 2015 11:55:36 +0800 Subject: add unix socket support to redis session driver --- .../Session/drivers/Session_redis_driver.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index b098cc441..f74067978 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -85,10 +85,24 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle { log_message('error', 'Session: No Redis save path configured.'); } + elseif (strpos($this->_config['save_path'], 'unix://') === 0 && preg_match('#(?:unix://)?([^:?]+)(\?.+)?#', $this->_config['save_path'], $matches)) + { + isset($matches[2]) OR $matches[2] = ''; // Just to avoid undefined index notices below + $this->_config['save_path'] = array( + 'type' => 'unix', + 'path' => $matches[1], + 'password' => preg_match('#auth=([^\s&]+)#', $matches[2], $match) ? $match[1] : NULL, + 'database' => preg_match('#database=(\d+)#', $matches[2], $match) ? (int) $match[1] : NULL, + 'timeout' => preg_match('#timeout=(\d+\.\d+)#', $matches[2], $match) ? (float) $match[1] : NULL + ); + + preg_match('#prefix=([^\s&]+)#', $matches[3], $match) && $this->_key_prefix = $match[1]; + } elseif (preg_match('#(?:tcp://)?([^:?]+)(?:\:(\d+))?(\?.+)?#', $this->_config['save_path'], $matches)) { isset($matches[3]) OR $matches[3] = ''; // Just to avoid undefined index notices below $this->_config['save_path'] = array( + 'type' => 'tcp', 'host' => $matches[1], 'port' => empty($matches[2]) ? NULL : $matches[2], 'password' => preg_match('#auth=([^\s&]+)#', $matches[3], $match) ? $match[1] : NULL, @@ -128,7 +142,11 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle } $redis = new Redis(); - if ( ! $redis->connect($this->_config['save_path']['host'], $this->_config['save_path']['port'], $this->_config['save_path']['timeout'])) + if ($this->_config['save_path']['type'] == 'unix' && !$redis->connect($this->_config['save_path']['path'])) + { + log_message('error', 'Session: Unable to connect to Redis with the configured settings.'); + } + else if ( ! $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.'); } -- cgit v1.2.3-24-g4f1b From 9703a0bbac81477365da7012a6a47d71c547cf96 Mon Sep 17 00:00:00 2001 From: kemeng Date: Mon, 16 Nov 2015 18:35:43 +0800 Subject: fixed a typo in unix socket parameter; change coding style to match CI; fix an elseif --- .../libraries/Session/drivers/Session_redis_driver.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index f74067978..fe82ca917 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -85,7 +85,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle { log_message('error', 'Session: No Redis save path configured.'); } - elseif (strpos($this->_config['save_path'], 'unix://') === 0 && preg_match('#(?:unix://)?([^:?]+)(\?.+)?#', $this->_config['save_path'], $matches)) + elseif (preg_match('#^unix://([^\?]+)(\?.+)?$#', $this->_config['save_path'], $matches)) { isset($matches[2]) OR $matches[2] = ''; // Just to avoid undefined index notices below $this->_config['save_path'] = array( @@ -96,7 +96,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle 'timeout' => preg_match('#timeout=(\d+\.\d+)#', $matches[2], $match) ? (float) $match[1] : NULL ); - preg_match('#prefix=([^\s&]+)#', $matches[3], $match) && $this->_key_prefix = $match[1]; + preg_match('#prefix=([^\s&]+)#', $matches[2], $match) && $this->_key_prefix = $match[1]; } elseif (preg_match('#(?:tcp://)?([^:?]+)(?:\:(\d+))?(\?.+)?#', $this->_config['save_path'], $matches)) { @@ -142,15 +142,19 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle } $redis = new Redis(); - if ($this->_config['save_path']['type'] == 'unix' && !$redis->connect($this->_config['save_path']['path'])) + if ($this->_config['save_path']['type'] == 'unix') { - log_message('error', 'Session: Unable to connect to Redis with the configured settings.'); + if (! $redis->connect($this->_config['save_path']['path'])) + { + log_message('error', 'Session: Unable to connect to Redis with the configured settings.'); + } } - else if ( ! $redis->connect($this->_config['save_path']['host'], $this->_config['save_path']['port'], $this->_config['save_path']['timeout'])) + 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.'); } - elseif (isset($this->_config['save_path']['password']) && ! $redis->auth($this->_config['save_path']['password'])) + + if (isset($this->_config['save_path']['password']) && ! $redis->auth($this->_config['save_path']['password'])) { log_message('error', 'Session: Unable to authenticate to Redis instance.'); } -- cgit v1.2.3-24-g4f1b From 47c37de5ec5f673b9db13a3c0f4d899fd651d703 Mon Sep 17 00:00:00 2001 From: kemeng Date: Mon, 16 Nov 2015 18:52:37 +0800 Subject: Spaces around ! . Changelog entry in 3.1.0. --- system/libraries/Session/drivers/Session_redis_driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index fe82ca917..44ffddc4b 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -144,12 +144,12 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle $redis = new Redis(); if ($this->_config['save_path']['type'] == 'unix') { - if (! $redis->connect($this->_config['save_path']['path'])) + if ( ! $redis->connect($this->_config['save_path']['path'])) { log_message('error', 'Session: Unable to connect to Redis with the configured settings.'); } } - elseif (! $redis->connect($this->_config['save_path']['host'], $this->_config['save_path']['port'], $this->_config['save_path']['timeout'])) + 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.'); } -- cgit v1.2.3-24-g4f1b 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/libraries/Session/drivers/Session_redis_driver.php') 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 From 0f6e5bc4d356680bae470f05ccb9e115dd57422e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 16 Nov 2015 16:17:07 +0200 Subject: [ci skip] Polish changes from PR #4240 --- .../Session/drivers/Session_redis_driver.php | 71 ++++++++++------------ 1 file changed, 33 insertions(+), 38 deletions(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index 8f9bcce24..4fa6c28b3 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -85,41 +85,39 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle { log_message('error', 'Session: No Redis save path configured.'); } - elseif (preg_match('#^unix://([^\?]+)(\?.+)?$#', $this->_config['save_path'], $matches)) + elseif (preg_match('#^unix://([^\?]+)(?\?.+)?$#', $this->_config['save_path'], $matches)) { - isset($matches[2]) OR $matches[2] = ''; // Just to avoid undefined index notices below - $this->_config['save_path'] = array( - 'type' => 'unix', - 'path' => $matches[1], - 'password' => preg_match('#auth=([^\s&]+)#', $matches[2], $match) ? $match[1] : NULL, - 'database' => preg_match('#database=(\d+)#', $matches[2], $match) ? (int) $match[1] : NULL, - 'timeout' => preg_match('#timeout=(\d+\.\d+)#', $matches[2], $match) ? (float) $match[1] : NULL - ); - - preg_match('#prefix=([^\s&]+)#', $matches[2], $match) && $this->_key_prefix = $match[1]; + $save_path = array('path' => $matches[1]); } - elseif (preg_match('#(?:tcp://)?([^:?]+)(?:\:(\d+))?(\?.+)?#', $this->_config['save_path'], $matches)) + elseif (preg_match('#(?:tcp://)?([^:?]+)(?:\:(\d+))?(?\?.+)?#', $this->_config['save_path'], $matches)) { - isset($matches[3]) OR $matches[3] = ''; // Just to avoid undefined index notices below - $this->_config['save_path'] = array( - 'type' => 'tcp', + $save_path = array( 'host' => $matches[1], - 'port' => empty($matches[2]) ? NULL : $matches[2], - 'password' => preg_match('#auth=([^\s&]+)#', $matches[3], $match) ? $match[1] : NULL, - 'database' => preg_match('#database=(\d+)#', $matches[3], $match) ? (int) $match[1] : NULL, - 'timeout' => preg_match('#timeout=(\d+\.\d+)#', $matches[3], $match) ? (float) $match[1] : NULL + 'port' => empty($matches[2]) ? NULL : $matches[2] ); - - preg_match('#prefix=([^\s&]+)#', $matches[3], $match) && $this->_key_prefix = $match[1]; } else { log_message('error', 'Session: Invalid Redis save path format: '.$this->_config['save_path']); } - if ($this->_config['match_ip'] === TRUE) + if (isset($save_path)) { - $this->_key_prefix .= $_SERVER['REMOTE_ADDR'].':'; + if (isset($matches['options'])) + { + $save_path['password'] = preg_match('#auth=([^\s&]+)#', $matches['options'], $match) ? $match[1] : NULL; + $save_path['database'] = preg_match('#database=(\d+)#', $matches['options'], $match) ? (int) $match[1] : NULL; + $save_path['timeout'] = preg_match('#timeout=(\d+\.\d+)#', $matches['options'], $match) ? (float) $match[1] : NULL; + + preg_match('#prefix=([^\s&]+)#', $matches['options'], $match) && $this->_key_prefix = $match[1]; + } + + $this->_config['save_path'] = $save_path; + + if ($this->_config['match_ip'] === TRUE) + { + $this->_key_prefix .= $_SERVER['REMOTE_ADDR'].':'; + } } } @@ -141,23 +139,16 @@ 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; - } + $connected = isset($this->_config['save_path']['path']) + ? $redis->connect($this->_config['save_path']['path']) + : $redis->connect( + $this->_config['save_path']['host'], + $this->_config['save_path']['port'], + $this->_config['save_path']['timeout'] + ); - if ($connected) + if ($connected) { if (isset($this->_config['save_path']['password']) && ! $redis->auth($this->_config['save_path']['password'])) { @@ -173,6 +164,10 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle return TRUE; } } + else + { + log_message('error', 'Session: Unable to connect to Redis with the configured settings.'); + } return FALSE; } -- cgit v1.2.3-24-g4f1b From 4dc17cf59142b3d3d80e9b3cdba77e7db0d2b75c Mon Sep 17 00:00:00 2001 From: Jonty Sewell Date: Wed, 3 Feb 2016 11:41:34 +0000 Subject: If attempting to write an empty session to Redis, a key will not actually be created, so when the driver tries to set the expiration timeout on the key, 0 is returned, triggering a warning from session_write_close Signed-off-by: Jonty Sewell --- system/libraries/Session/drivers/Session_redis_driver.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index c7c574202..aa8459bef 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -240,9 +240,15 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle return $this->_failure; } - return ($this->_redis->setTimeout($this->_key_prefix.$session_id, $this->_config['expiration'])) - ? $this->_success - : $this->_failure; + if($this->_fingerprint === md5('')) + { + // A blank session will not be written to redis, so a timeout cannot be set on it + return $this->_success; + } else { + return ($this->_redis->setTimeout($this->_key_prefix.$session_id, $this->_config['expiration'])) + ? $this->_success + : $this->_failure; + } } return $this->_failure; -- cgit v1.2.3-24-g4f1b From 880036d5cea0021258c43c0d0fba0e6fd9d04b69 Mon Sep 17 00:00:00 2001 From: Jonty Sewell Date: Fri, 5 Feb 2016 09:27:47 +0000 Subject: Revert previous changes - fixing the source of the problem rather than working around it Signed-off-by: Jonty Sewell --- system/libraries/Session/drivers/Session_redis_driver.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index aa8459bef..c7c574202 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -240,15 +240,9 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle return $this->_failure; } - if($this->_fingerprint === md5('')) - { - // A blank session will not be written to redis, so a timeout cannot be set on it - return $this->_success; - } else { - return ($this->_redis->setTimeout($this->_key_prefix.$session_id, $this->_config['expiration'])) - ? $this->_success - : $this->_failure; - } + return ($this->_redis->setTimeout($this->_key_prefix.$session_id, $this->_config['expiration'])) + ? $this->_success + : $this->_failure; } return $this->_failure; -- cgit v1.2.3-24-g4f1b From 74f846890d69e6f5ff5f0bb4268539803242d015 Mon Sep 17 00:00:00 2001 From: Jonty Sewell Date: Fri, 5 Feb 2016 09:39:05 +0000 Subject: Add a flag to determine whether the redis key currently exists, and if not, force creation of it at write-time Signed-off-by: Jonty Sewell --- .../Session/drivers/Session_redis_driver.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index c7c574202..e62a3c597 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -69,6 +69,13 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle */ protected $_lock_key; + /** + * Key exists flag + * + * @var boolean + */ + protected $_key_exists = FALSE; + // ------------------------------------------------------------------------ /** @@ -189,7 +196,15 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle // Needed by write() to detect session_regenerate_id() calls $this->_session_id = $session_id; - $session_data = (string) $this->_redis->get($this->_key_prefix.$session_id); + $session_data = $this->_redis->get($this->_key_prefix.$session_id); + + if ($session_data === FALSE) + { + // The session ID does not exist in redis yet, so set a flag to create it + $this->_key_exists = FALSE; + $session_data = ''; + } + $this->_fingerprint = md5($session_data); return $session_data; } @@ -229,7 +244,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle if (isset($this->_lock_key)) { $this->_redis->setTimeout($this->_lock_key, 300); - if ($this->_fingerprint !== ($fingerprint = md5($session_data))) + if ($this->_fingerprint !== ($fingerprint = md5($session_data)) OR $this->_key_exists === FALSE) { if ($this->_redis->set($this->_key_prefix.$session_id, $session_data, $this->_config['expiration'])) { -- cgit v1.2.3-24-g4f1b From a7f9ea28aa40bd036de1cee7a4ec4ab63235fd12 Mon Sep 17 00:00:00 2001 From: Jonty Sewell Date: Fri, 5 Feb 2016 10:33:00 +0000 Subject: Set the _key_exists flag to TRUE when the key does in fact exist. Set it to FALSE if the ID is being regenerated, and set it to TRUE once it's been written. Signed-off-by: Jonty Sewell --- system/libraries/Session/drivers/Session_redis_driver.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index e62a3c597..be5b37e81 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -72,7 +72,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle /** * Key exists flag * - * @var boolean + * @var bool */ protected $_key_exists = FALSE; @@ -204,6 +204,10 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle $this->_key_exists = FALSE; $session_data = ''; } + else + { + $this->_key_exists = TRUE; + } $this->_fingerprint = md5($session_data); return $session_data; @@ -237,7 +241,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle return $this->_failure; } - $this->_fingerprint = md5(''); + $this->_key_exists = FALSE; $this->_session_id = $session_id; } @@ -249,6 +253,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle if ($this->_redis->set($this->_key_prefix.$session_id, $session_data, $this->_config['expiration'])) { $this->_fingerprint = $fingerprint; + $this->_key_exists = TRUE; return $this->_success; } -- cgit v1.2.3-24-g4f1b From 0f19fd0550e95354e8512c28ff19799aa913c0f9 Mon Sep 17 00:00:00 2001 From: Jonty Sewell Date: Fri, 5 Feb 2016 10:38:43 +0000 Subject: Setting the flag to FALSE is unnecessary since it defaults to FALSE, therefore this block of code can be reduced to a single statement Signed-off-by: Jonty Sewell --- system/libraries/Session/drivers/Session_redis_driver.php | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index be5b37e81..c4483e439 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -198,16 +198,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle $session_data = $this->_redis->get($this->_key_prefix.$session_id); - if ($session_data === FALSE) - { - // The session ID does not exist in redis yet, so set a flag to create it - $this->_key_exists = FALSE; - $session_data = ''; - } - else - { - $this->_key_exists = TRUE; - } + is_string($session_data) && $this->_key_exists = TRUE; $this->_fingerprint = md5($session_data); return $session_data; -- cgit v1.2.3-24-g4f1b From c07ae0888377fb434ce70d0817746962722ea3b1 Mon Sep 17 00:00:00 2001 From: Jonty Sewell Date: Fri, 5 Feb 2016 12:34:01 +0000 Subject: Fix regression on PHP7 when regenerating the session (#4362) --- system/libraries/Session/drivers/Session_redis_driver.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index c4483e439..dc4328644 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -198,7 +198,9 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle $session_data = $this->_redis->get($this->_key_prefix.$session_id); - is_string($session_data) && $this->_key_exists = TRUE; + is_string($session_data) + ? $this->_key_exists = TRUE + : $session_data = ''; $this->_fingerprint = md5($session_data); return $session_data; -- cgit v1.2.3-24-g4f1b From b89f5d3ddfc897f0afc4f15a0993f8f1b2b56b88 Mon Sep 17 00:00:00 2001 From: roastduck Date: Sun, 28 Feb 2016 10:18:19 +0800 Subject: clean current lock key in redis session driver set $this->_lock_key to NULL after close Signed-off-by: roastduck --- system/libraries/Session/drivers/Session_redis_driver.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index dc4328644..5081bd5d4 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -278,6 +278,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle if ($this->_redis->ping() === '+PONG') { isset($this->_lock_key) && $this->_redis->delete($this->_lock_key); + $this->_lock_key = NULL; if ($this->_redis->close() === $this->_failure) { return $this->_failure; -- cgit v1.2.3-24-g4f1b From 7f0f73ba81ad712f2553e2f7ef5d0a50f16e119e Mon Sep 17 00:00:00 2001 From: __RD Date: Mon, 29 Feb 2016 22:56:29 +0800 Subject: delete lock directly -> call _release_lock() --- system/libraries/Session/drivers/Session_redis_driver.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index 5081bd5d4..3b648d183 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -277,8 +277,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle try { if ($this->_redis->ping() === '+PONG') { - isset($this->_lock_key) && $this->_redis->delete($this->_lock_key); - $this->_lock_key = NULL; + $this->_release_lock($this->_lock_key); if ($this->_redis->close() === $this->_failure) { return $this->_failure; -- cgit v1.2.3-24-g4f1b From 9a15344bc610b2c6a3a1a0a0b73db2fe0eba987a Mon Sep 17 00:00:00 2001 From: __RD Date: Mon, 29 Feb 2016 22:58:23 +0800 Subject: fix typo --- system/libraries/Session/drivers/Session_redis_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index 3b648d183..c0c20a7ca 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -277,7 +277,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle try { if ($this->_redis->ping() === '+PONG') { - $this->_release_lock($this->_lock_key); + $this->_release_lock(); if ($this->_redis->close() === $this->_failure) { return $this->_failure; -- cgit v1.2.3-24-g4f1b From e12fcec770d7bc03f746c291e96cc75b51475f74 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 19 Jul 2016 13:37:40 +0300 Subject: [ci skip] Fix an undefined index for 'timeout' in Redis session driver http://forum.codeigniter.com/thread-64219.html --- system/libraries/Session/drivers/Session_redis_driver.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index ad14cbfdc..d3a265958 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -99,8 +99,9 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle elseif (preg_match('#(?:tcp://)?([^:?]+)(?:\:(\d+))?(?\?.+)?#', $this->_config['save_path'], $matches)) { $save_path = array( - 'host' => $matches[1], - 'port' => empty($matches[2]) ? NULL : $matches[2] + 'host' => $matches[1], + 'port' => empty($matches[2]) ? NULL : $matches[2], + 'timeout' => NULL // We always pass this to Redis::connect(), so it needs to exist ); } else -- cgit v1.2.3-24-g4f1b From fced25f5728ce81fe810216fcaa4ccec7523f6c9 Mon Sep 17 00:00:00 2001 From: Master Yoda Date: Sat, 31 Dec 2016 08:46:18 -0800 Subject: Update copyright data to 2017 --- system/libraries/Session/drivers/Session_redis_driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index 233b15619..5313de04c 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014 - 2016, British Columbia Institute of Technology + * Copyright (c) 2014 - 2017, British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) - * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) + * @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com * @since Version 3.0.0 -- cgit v1.2.3-24-g4f1b From dec2b56fa44803e1579804fe329fd45658c6217b Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Sun, 4 Jun 2017 23:08:40 -0700 Subject: Fix misc type inconsistencies between code and doc comments --- system/libraries/Session/drivers/Session_redis_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index 5313de04c..2aeb77267 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -51,7 +51,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle /** * phpRedis instance * - * @var resource + * @var Redis */ protected $_redis; -- cgit v1.2.3-24-g4f1b From 569cf69078de1c8a970ab4259467dfe27b4cdb96 Mon Sep 17 00:00:00 2001 From: tianhe1986 Date: Wed, 5 Jul 2017 16:54:01 +0800 Subject: Acquiring redis lock with existence check. Signed-off-by: tianhe1986 --- system/libraries/Session/drivers/Session_redis_driver.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index 2aeb77267..8fc0a45da 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -365,7 +365,16 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle continue; } - if ( ! $this->_redis->setex($lock_key, 300, time())) + if ($ttl === -2) + { + $set_result = $this->_redis->set($lock_key, time(), array('nx', 'ex' => 300)); + } + else + { + $set_result = $this->_redis->setex($lock_key, 300, time()); + } + + if ( ! $set_result) { log_message('error', 'Session: Error while trying to obtain lock for '.$this->_key_prefix.$session_id); return FALSE; -- cgit v1.2.3-24-g4f1b From 3eecd968bd68cf3c70baa81be332b2007a14e564 Mon Sep 17 00:00:00 2001 From: tianhe1986 Date: Wed, 5 Jul 2017 19:42:49 +0800 Subject: Simplifying the code. Signed-off-by: tianhe1986 --- system/libraries/Session/drivers/Session_redis_driver.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index 8fc0a45da..3437898de 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -365,16 +365,10 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle continue; } - if ($ttl === -2) - { - $set_result = $this->_redis->set($lock_key, time(), array('nx', 'ex' => 300)); - } - else - { - $set_result = $this->_redis->setex($lock_key, 300, time()); - } - - if ( ! $set_result) + $result = ($ttl === -2) + ? $this->_redis->set($lock_key, time(), array('nx', 'ex' => 300)) + : $this->_redis->setex($lock_key, 300, time()); + if ( ! $result) { log_message('error', 'Session: Error while trying to obtain lock for '.$this->_key_prefix.$session_id); return FALSE; -- cgit v1.2.3-24-g4f1b From 24e91311bd86b9eddb9ffb2d4b6ab78bf19796c2 Mon Sep 17 00:00:00 2001 From: tianhe1986 Date: Thu, 6 Jul 2017 09:25:01 +0800 Subject: Format fixing. Signed-off-by: tianhe1986 --- system/libraries/Session/drivers/Session_redis_driver.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index 3437898de..76bddffd3 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -368,6 +368,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle $result = ($ttl === -2) ? $this->_redis->set($lock_key, time(), array('nx', 'ex' => 300)) : $this->_redis->setex($lock_key, 300, time()); + if ( ! $result) { log_message('error', 'Session: Error while trying to obtain lock for '.$this->_key_prefix.$session_id); -- cgit v1.2.3-24-g4f1b From 208381009ed12768478b2e8110bfb6e506acc3e1 Mon Sep 17 00:00:00 2001 From: Master Yoda Date: Tue, 9 Jan 2018 00:53:27 -0800 Subject: Annual copyright update --- system/libraries/Session/drivers/Session_redis_driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index 76bddffd3..3882c13a1 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014 - 2017, British Columbia Institute of Technology + * Copyright (c) 2014 - 2018, British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) - * @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/) + * @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com * @since Version 3.0.0 -- cgit v1.2.3-24-g4f1b From 52a87e506d4fc70bd5922b07a532852d28f28ab6 Mon Sep 17 00:00:00 2001 From: Mehdi Bounya Date: Thu, 17 May 2018 23:41:30 +0000 Subject: http:// to https:// --- system/libraries/Session/drivers/Session_redis_driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index 3882c13a1..0fee40e3a 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -29,8 +29,8 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) - * @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/) - * @license http://opensource.org/licenses/MIT MIT License + * @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (https://bcit.ca/) + * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com * @since Version 3.0.0 * @filesource -- cgit v1.2.3-24-g4f1b From 8bb638e392f5991c05ec9a1e57b882213844dc6f Mon Sep 17 00:00:00 2001 From: Jim Parry Date: Wed, 26 Dec 2018 21:03:09 -0800 Subject: Update copyright date to 2019 --- system/libraries/Session/drivers/Session_redis_driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index 0562301b2..6020a9ef9 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014 - 2018, British Columbia Institute of Technology + * Copyright (c) 2014 - 2019, British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) - * @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (https://bcit.ca/) + * @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com * @since Version 3.0.0 -- cgit v1.2.3-24-g4f1b From 2fbe1fa8e6515f603ac788f2f49c83ba24f485eb Mon Sep 17 00:00:00 2001 From: Michael Long Date: Sat, 2 Mar 2019 18:36:17 +0800 Subject: Resolve race condition in redis driven session key get_lock --- system/libraries/Session/drivers/Session_redis_driver.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index 07511e555..7262a2300 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -389,8 +389,9 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle if ( ! $result) { - log_message('error', 'Session: Error while trying to obtain lock for '.$this->_key_prefix.$session_id); - return FALSE; + // Sleep for 0.1s to wait for lock releases. + usleep(100000); + continue; } $this->_lock_key = $lock_key; -- cgit v1.2.3-24-g4f1b From 7f8e0cd333176ee943e0c46eb9fe10d31b70d3ce Mon Sep 17 00:00:00 2001 From: Michael Long Date: Fri, 15 Mar 2019 10:47:49 +0800 Subject: Refactor behaviors with different ttl of lock_key --- system/libraries/Session/drivers/Session_redis_driver.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index 7262a2300..c9a98b822 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -383,16 +383,16 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle continue; } - $result = ($ttl === -2) - ? $this->_redis->set($lock_key, time(), array('nx', 'ex' => 300)) - : $this->_redis->setex($lock_key, 300, time()); - - if ( ! $result) + if ($ttl === -2 && ! $this->_redis->set($lock_key, time(), array('nx', 'ex' => 300))) { - // Sleep for 0.1s to wait for lock releases. - usleep(100000); + // Sleep for 1s to wait for lock releases. + sleep(1); continue; } + elseif ($ttl === -1 && ! $this->_redis->setex($lock_key, 300, time())) { + log_message('error', 'Session: Error while trying to obtain lock for '.$this->_key_prefix.$session_id); + return FALSE; + } $this->_lock_key = $lock_key; break; -- cgit v1.2.3-24-g4f1b From d3bdd3c973508ff89e6f6789521f2e2476099cfa Mon Sep 17 00:00:00 2001 From: Michael Long Date: Fri, 15 Mar 2019 11:38:30 +0800 Subject: Fix code style --- system/libraries/Session/drivers/Session_redis_driver.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index c9a98b822..08b299f9c 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -389,7 +389,8 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle sleep(1); continue; } - elseif ($ttl === -1 && ! $this->_redis->setex($lock_key, 300, time())) { + elseif ($ttl === -1 && ! $this->_redis->setex($lock_key, 300, time())) + { log_message('error', 'Session: Error while trying to obtain lock for '.$this->_key_prefix.$session_id); return FALSE; } -- cgit v1.2.3-24-g4f1b From 06739bdc05f2fa5fc92db0675ec48f7374ae50cf Mon Sep 17 00:00:00 2001 From: Michael Long Date: Sat, 16 Mar 2019 00:17:06 +0800 Subject: Remove unnecessary code --- system/libraries/Session/drivers/Session_redis_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index 08b299f9c..c90e94bd3 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -389,7 +389,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle sleep(1); continue; } - elseif ($ttl === -1 && ! $this->_redis->setex($lock_key, 300, time())) + elseif ( ! $this->_redis->setex($lock_key, 300, time())) { log_message('error', 'Session: Error while trying to obtain lock for '.$this->_key_prefix.$session_id); return FALSE; -- cgit v1.2.3-24-g4f1b From e0bdd367067a8231a4c2a8c9589c2e286b6fde6f Mon Sep 17 00:00:00 2001 From: George Petculescu Date: Tue, 18 Jun 2019 21:38:53 +0300 Subject: Calling php5_validate_id() in the right place, for Redis session driver --- system/libraries/Session/drivers/Session_redis_driver.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index c90e94bd3..9ff6a0e1f 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -168,6 +168,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle } else { + $this->php5_validate_id(); $this->_redis = $redis; return $this->_success; } @@ -177,8 +178,6 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle log_message('error', 'Session: Unable to connect to Redis with the configured settings.'); } - $this->php5_validate_id(); - return $this->_fail(); } -- cgit v1.2.3-24-g4f1b From 7d741c2ba0cc694b57469c692bb0b197e0127e95 Mon Sep 17 00:00:00 2001 From: Michael Long Date: Mon, 12 Aug 2019 11:58:40 +0800 Subject: Adapt to new version of php-redis --- .../Session/drivers/Session_redis_driver.php | 45 +++++++++++++++++++--- 1 file changed, 39 insertions(+), 6 deletions(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index 9ff6a0e1f..4976e9473 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -240,7 +240,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle $this->_session_id = $session_id; } - $this->_redis->setTimeout($this->_lock_key, 300); + $this->_expire($this->_lock_key, 300); if ($this->_fingerprint !== ($fingerprint = md5($session_data)) OR $this->_key_exists === FALSE) { if ($this->_redis->set($this->_key_prefix.$session_id, $session_data, $this->_config['expiration'])) @@ -253,7 +253,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle return $this->_fail(); } - return ($this->_redis->setTimeout($this->_key_prefix.$session_id, $this->_config['expiration'])) + return ($this->_expire($this->_key_prefix.$session_id, $this->_config['expiration'])) ? $this->_success : $this->_fail(); } @@ -272,7 +272,8 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle if (isset($this->_redis)) { try { - if ($this->_redis->ping() === '+PONG') + $ping = $this->_redis->ping(); + if ($ping === '+PONG' || $ping === TRUE) { $this->_release_lock(); if ($this->_redis->close() === FALSE) @@ -307,9 +308,9 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle { if (isset($this->_redis, $this->_lock_key)) { - if (($result = $this->_redis->delete($this->_key_prefix.$session_id)) !== 1) + if (($result = $this->_delete($this->_key_prefix.$session_id)) !== 1) { - log_message('debug', 'Session: Redis::delete() expected to return 1, got '.var_export($result, TRUE).' instead.'); + log_message('debug', 'Session: Redis::del() expected to return 1, got '.var_export($result, TRUE).' instead.'); } $this->_cookie_destroy(); @@ -368,7 +369,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle // correct session ID. if ($this->_lock_key === $this->_key_prefix.$session_id.':lock') { - return $this->_redis->setTimeout($this->_lock_key, 300); + return $this->_expire($this->_lock_key, 300); } // 30 attempts to obtain a lock, in case another request already has it @@ -439,4 +440,36 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle return TRUE; } + // ------------------------------------------------------------------------ + + /** + * Expire + * + * Sets expiration for a key + * + * @return bool + */ + protected function _expire($key, $timeout) + { + if (method_exists($this->_redis, 'expire')) + return $this->_redis->expire($key, $timeout); + return $this->_redis->setTimeout($key, $timeout); + } + + // ------------------------------------------------------------------------ + + /** + * Delete + * + * Deletes a key + * + * @return bool + */ + protected function _delete($key) + { + if (method_exists($this->_redis, 'del')) + return $this->_redis->del($key); + return $this->_redis->delete($key); + } + } -- cgit v1.2.3-24-g4f1b From 4aec0ed32942b52535b69bfbe33ff9e8e957b245 Mon Sep 17 00:00:00 2001 From: Michael Long Date: Mon, 12 Aug 2019 12:25:22 +0800 Subject: Add parameter description --- system/libraries/Session/drivers/Session_redis_driver.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index 4976e9473..1f1004fb9 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -447,13 +447,15 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle * * Sets expiration for a key * + * @param string $key Redis key + * @param int $ttl The key's remaining Time To Live, in seconds. * @return bool */ - protected function _expire($key, $timeout) + protected function _expire($key, $ttl) { if (method_exists($this->_redis, 'expire')) - return $this->_redis->expire($key, $timeout); - return $this->_redis->setTimeout($key, $timeout); + return $this->_redis->expire($key, $ttl); + return $this->_redis->setTimeout($key, $ttl); } // ------------------------------------------------------------------------ @@ -463,6 +465,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle * * Deletes a key * + * @param string $key Redis key * @return bool */ protected function _delete($key) -- cgit v1.2.3-24-g4f1b From 8535d803b8feb252c6f4a14b5e87a47111f1d4a8 Mon Sep 17 00:00:00 2001 From: Michael Long Date: Wed, 14 Aug 2019 03:13:10 +0800 Subject: Adapt to styleguide --- .../Session/drivers/Session_redis_driver.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index 1f1004fb9..3323ca6cf 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -240,7 +240,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle $this->_session_id = $session_id; } - $this->_expire($this->_lock_key, 300); + $this->_expire_key($this->_lock_key, 300); if ($this->_fingerprint !== ($fingerprint = md5($session_data)) OR $this->_key_exists === FALSE) { if ($this->_redis->set($this->_key_prefix.$session_id, $session_data, $this->_config['expiration'])) @@ -253,7 +253,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle return $this->_fail(); } - return ($this->_expire($this->_key_prefix.$session_id, $this->_config['expiration'])) + return ($this->_expire_key($this->_key_prefix.$session_id, $this->_config['expiration'])) ? $this->_success : $this->_fail(); } @@ -273,7 +273,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle { try { $ping = $this->_redis->ping(); - if ($ping === '+PONG' || $ping === TRUE) + if ($ping === '+PONG' OR $ping === TRUE) { $this->_release_lock(); if ($this->_redis->close() === FALSE) @@ -308,7 +308,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle { if (isset($this->_redis, $this->_lock_key)) { - if (($result = $this->_delete($this->_key_prefix.$session_id)) !== 1) + if (($result = $this->_delete_key($this->_key_prefix.$session_id)) !== 1) { log_message('debug', 'Session: Redis::del() expected to return 1, got '.var_export($result, TRUE).' instead.'); } @@ -369,7 +369,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle // correct session ID. if ($this->_lock_key === $this->_key_prefix.$session_id.':lock') { - return $this->_expire($this->_lock_key, 300); + return $this->_expire_key($this->_lock_key, 300); } // 30 attempts to obtain a lock, in case another request already has it @@ -443,15 +443,15 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle // ------------------------------------------------------------------------ /** - * Expire + * Expire key * * Sets expiration for a key * * @param string $key Redis key - * @param int $ttl The key's remaining Time To Live, in seconds. + * @param int $ttl The key's remaining Time To Live, in seconds. * @return bool */ - protected function _expire($key, $ttl) + protected function _expire_key($key, $ttl) { if (method_exists($this->_redis, 'expire')) return $this->_redis->expire($key, $ttl); @@ -461,14 +461,14 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle // ------------------------------------------------------------------------ /** - * Delete + * Delete key * * Deletes a key * * @param string $key Redis key * @return bool */ - protected function _delete($key) + protected function _delete_key($key) { if (method_exists($this->_redis, 'del')) return $this->_redis->del($key); -- cgit v1.2.3-24-g4f1b From 1f90f7b985214319b1363d0fa2b497d2a1cd9a8d Mon Sep 17 00:00:00 2001 From: Michael Long Date: Wed, 14 Aug 2019 03:22:16 +0800 Subject: Use version_compare to avoid method checks --- system/libraries/Session/drivers/Session_redis_driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index 3323ca6cf..66a28ffdc 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -453,7 +453,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle */ protected function _expire_key($key, $ttl) { - if (method_exists($this->_redis, 'expire')) + if (version_compare(phpversion('redis'), '5', '>=')) return $this->_redis->expire($key, $ttl); return $this->_redis->setTimeout($key, $ttl); } @@ -470,7 +470,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle */ protected function _delete_key($key) { - if (method_exists($this->_redis, 'del')) + if (version_compare(phpversion('redis'), '5', '>=')) return $this->_redis->del($key); return $this->_redis->delete($key); } -- cgit v1.2.3-24-g4f1b From 940819167f58bad7efb87b9dacd91ba44029ab4d Mon Sep 17 00:00:00 2001 From: Michael Long Date: Wed, 14 Aug 2019 18:36:38 +0800 Subject: Define constant PHPREDIS_VERSION --- system/libraries/Session/drivers/Session_redis_driver.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index 66a28ffdc..1215b3afd 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -37,6 +37,8 @@ */ defined('BASEPATH') OR exit('No direct script access allowed'); +define('PHPREDIS_VERSION', phpversion('redis')); + /** * CodeIgniter Session Redis Driver * @@ -453,7 +455,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle */ protected function _expire_key($key, $ttl) { - if (version_compare(phpversion('redis'), '5', '>=')) + if (version_compare(PHPREDIS_VERSION, '5', '>=')) return $this->_redis->expire($key, $ttl); return $this->_redis->setTimeout($key, $ttl); } @@ -470,7 +472,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle */ protected function _delete_key($key) { - if (version_compare(phpversion('redis'), '5', '>=')) + if (version_compare(PHPREDIS_VERSION, '5', '>=')) return $this->_redis->del($key); return $this->_redis->delete($key); } -- cgit v1.2.3-24-g4f1b From 8ae161944fe2c25e1fc56e845cf66b07d65805dd Mon Sep 17 00:00:00 2001 From: Michael Long Date: Fri, 23 Aug 2019 22:07:43 +0800 Subject: Refactor implementation of #5816 --- .../Session/drivers/Session_redis_driver.php | 77 ++++++++++++++++------ 1 file changed, 56 insertions(+), 21 deletions(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index 1215b3afd..3ee59a4a2 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -37,8 +37,6 @@ */ defined('BASEPATH') OR exit('No direct script access allowed'); -define('PHPREDIS_VERSION', phpversion('redis')); - /** * CodeIgniter Session Redis Driver * @@ -78,6 +76,33 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle */ protected $_key_exists = FALSE; + /** + * Name of setTimeout() method in phpRedis + * + * Due to some deprecated methods in phpRedis, we need to call the + * specific methods depending on the version of phpRedis. + * + * @var string + */ + protected $_setTimeout_name; + + /** + * Name of delete() method in phpRedis + * + * Due to some deprecated methods in phpRedis, we need to call the + * specific methods depending on the version of phpRedis. + * + * @var string + */ + protected $_delete_name; + + /** + * Response of ping() method in phpRedis + * + * @var mixed + */ + protected $_ping_response; + // ------------------------------------------------------------------------ /** @@ -90,6 +115,20 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle { parent::__construct($params); + // Detect the names of some methods in phpRedis instance + if (version_compare(phpversion('redis'), '5', '>=')) + { + $this->_setTimeout_name = 'expire'; + $this->_delete_name = 'del'; + $this->_ping_response = TRUE; + } + else + { + $this->_setTimeout_name = 'setTimeout'; + $this->_delete_name = 'delete'; + $this->_ping_response = '+PONG'; + } + if (empty($this->_config['save_path'])) { log_message('error', 'Session: No Redis save path configured.'); @@ -170,8 +209,8 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle } else { - $this->php5_validate_id(); $this->_redis = $redis; + $this->php5_validate_id(); return $this->_success; } } @@ -242,7 +281,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle $this->_session_id = $session_id; } - $this->_expire_key($this->_lock_key, 300); + $this->_setTimeout($this->_lock_key, 300); if ($this->_fingerprint !== ($fingerprint = md5($session_data)) OR $this->_key_exists === FALSE) { if ($this->_redis->set($this->_key_prefix.$session_id, $session_data, $this->_config['expiration'])) @@ -255,7 +294,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle return $this->_fail(); } - return ($this->_expire_key($this->_key_prefix.$session_id, $this->_config['expiration'])) + return ($this->_setTimeout($this->_key_prefix.$session_id, $this->_config['expiration'])) ? $this->_success : $this->_fail(); } @@ -275,7 +314,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle { try { $ping = $this->_redis->ping(); - if ($ping === '+PONG' OR $ping === TRUE) + if ($ping === $this->_ping_response) { $this->_release_lock(); if ($this->_redis->close() === FALSE) @@ -310,9 +349,9 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle { if (isset($this->_redis, $this->_lock_key)) { - if (($result = $this->_delete_key($this->_key_prefix.$session_id)) !== 1) + if (($result = $this->_delete($this->_key_prefix.$session_id)) !== 1) { - log_message('debug', 'Session: Redis::del() expected to return 1, got '.var_export($result, TRUE).' instead.'); + log_message('debug', 'Session: Redis::'.$this->_delete_name.'() expected to return 1, got '.var_export($result, TRUE).' instead.'); } $this->_cookie_destroy(); @@ -371,7 +410,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle // correct session ID. if ($this->_lock_key === $this->_key_prefix.$session_id.':lock') { - return $this->_expire_key($this->_lock_key, 300); + return $this->_setTimeout($this->_lock_key, 300); } // 30 attempts to obtain a lock, in case another request already has it @@ -429,7 +468,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle { if (isset($this->_redis, $this->_lock_key) && $this->_lock) { - if ( ! $this->_redis->delete($this->_lock_key)) + if ( ! $this->_delete($this->_lock_key)) { log_message('error', 'Session: Error while trying to free lock for '.$this->_lock_key); return FALSE; @@ -445,7 +484,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle // ------------------------------------------------------------------------ /** - * Expire key + * Set timeout * * Sets expiration for a key * @@ -453,28 +492,24 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle * @param int $ttl The key's remaining Time To Live, in seconds. * @return bool */ - protected function _expire_key($key, $ttl) + protected function _setTimeout($key, $ttl) { - if (version_compare(PHPREDIS_VERSION, '5', '>=')) - return $this->_redis->expire($key, $ttl); - return $this->_redis->setTimeout($key, $ttl); + return $this->_redis->{$this->_setTimeout_name}($key, $ttl); } // ------------------------------------------------------------------------ /** - * Delete key + * Delete * * Deletes a key * - * @param string $key Redis key + * @param string $key Redis key * @return bool */ - protected function _delete_key($key) + protected function _delete($key) { - if (version_compare(PHPREDIS_VERSION, '5', '>=')) - return $this->_redis->del($key); - return $this->_redis->delete($key); + return $this->_redis->{$this->_delete_name}($key); } } -- cgit v1.2.3-24-g4f1b From a9f13251df09ceb179ce6a9f6440a6869e779bba Mon Sep 17 00:00:00 2001 From: Michael Long Date: Wed, 4 Sep 2019 01:11:04 +0800 Subject: Delete unnecessary functions --- .../Session/drivers/Session_redis_driver.php | 44 +++------------------- 1 file changed, 6 insertions(+), 38 deletions(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index 3ee59a4a2..ea70e4946 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -281,7 +281,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle $this->_session_id = $session_id; } - $this->_setTimeout($this->_lock_key, 300); + $this->_redis->{$this->_setTimeout_name}($this->_lock_key, 300); if ($this->_fingerprint !== ($fingerprint = md5($session_data)) OR $this->_key_exists === FALSE) { if ($this->_redis->set($this->_key_prefix.$session_id, $session_data, $this->_config['expiration'])) @@ -294,7 +294,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle return $this->_fail(); } - return ($this->_setTimeout($this->_key_prefix.$session_id, $this->_config['expiration'])) + return ($this->_redis->{$this->_setTimeout_name}($this->_key_prefix.$session_id, $this->_config['expiration'])) ? $this->_success : $this->_fail(); } @@ -313,8 +313,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle if (isset($this->_redis)) { try { - $ping = $this->_redis->ping(); - if ($ping === $this->_ping_response) + if ($this->_redis->ping() === $this->_ping_response) { $this->_release_lock(); if ($this->_redis->close() === FALSE) @@ -349,7 +348,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle { if (isset($this->_redis, $this->_lock_key)) { - if (($result = $this->_delete($this->_key_prefix.$session_id)) !== 1) + if (($result = $this->_redis->{$this->_delete_name}($this->_key_prefix.$session_id)) !== 1) { log_message('debug', 'Session: Redis::'.$this->_delete_name.'() expected to return 1, got '.var_export($result, TRUE).' instead.'); } @@ -410,7 +409,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle // correct session ID. if ($this->_lock_key === $this->_key_prefix.$session_id.':lock') { - return $this->_setTimeout($this->_lock_key, 300); + return $this->_redis->{$this->_setTimeout_name}($this->_lock_key, 300); } // 30 attempts to obtain a lock, in case another request already has it @@ -468,7 +467,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle { if (isset($this->_redis, $this->_lock_key) && $this->_lock) { - if ( ! $this->_delete($this->_lock_key)) + if ( ! $this->_redis->{$this->_delete_name}($this->_lock_key)) { log_message('error', 'Session: Error while trying to free lock for '.$this->_lock_key); return FALSE; @@ -481,35 +480,4 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle return TRUE; } - // ------------------------------------------------------------------------ - - /** - * Set timeout - * - * Sets expiration for a key - * - * @param string $key Redis key - * @param int $ttl The key's remaining Time To Live, in seconds. - * @return bool - */ - protected function _setTimeout($key, $ttl) - { - return $this->_redis->{$this->_setTimeout_name}($key, $ttl); - } - - // ------------------------------------------------------------------------ - - /** - * Delete - * - * Deletes a key - * - * @param string $key Redis key - * @return bool - */ - protected function _delete($key) - { - return $this->_redis->{$this->_delete_name}($key); - } - } -- cgit v1.2.3-24-g4f1b From b373b9b099a5df0b180128d83fb3bf3f44877280 Mon Sep 17 00:00:00 2001 From: Michael Long Date: Wed, 4 Sep 2019 01:13:50 +0800 Subject: Rename to _ping_success --- system/libraries/Session/drivers/Session_redis_driver.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index ea70e4946..cb6bf3645 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -97,11 +97,11 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle protected $_delete_name; /** - * Response of ping() method in phpRedis + * Success return value of ping() method in phpRedis * * @var mixed */ - protected $_ping_response; + protected $_ping_success; // ------------------------------------------------------------------------ @@ -120,13 +120,13 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle { $this->_setTimeout_name = 'expire'; $this->_delete_name = 'del'; - $this->_ping_response = TRUE; + $this->_ping_success = TRUE; } else { $this->_setTimeout_name = 'setTimeout'; $this->_delete_name = 'delete'; - $this->_ping_response = '+PONG'; + $this->_ping_success = '+PONG'; } if (empty($this->_config['save_path'])) @@ -313,7 +313,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle if (isset($this->_redis)) { try { - if ($this->_redis->ping() === $this->_ping_response) + if ($this->_redis->ping() === $this->_ping_success) { $this->_release_lock(); if ($this->_redis->close() === FALSE) -- cgit v1.2.3-24-g4f1b From e5175991d6b8488f7e6ef37dbd2771b4f210a574 Mon Sep 17 00:00:00 2001 From: Michael Long Date: Wed, 4 Sep 2019 01:14:49 +0800 Subject: revert: Alter php_validate_id() --- system/libraries/Session/drivers/Session_redis_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index cb6bf3645..3a5b34e69 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -209,8 +209,8 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle } else { - $this->_redis = $redis; $this->php5_validate_id(); + $this->_redis = $redis; return $this->_success; } } -- cgit v1.2.3-24-g4f1b From b83c5072d8a359c09dbb99d280193608b802ac3f Mon Sep 17 00:00:00 2001 From: Michael Long Date: Wed, 4 Sep 2019 01:25:03 +0800 Subject: Alter php5_validate_id() --- system/libraries/Session/drivers/Session_redis_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index 9ff6a0e1f..33295cb45 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -168,8 +168,8 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle } else { - $this->php5_validate_id(); $this->_redis = $redis; + $this->php5_validate_id(); return $this->_success; } } -- cgit v1.2.3-24-g4f1b From dd4c143ef12ccab9dd57991677ced85a4756ce1e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 5 Sep 2019 15:48:28 +0300 Subject: [ci skip] Remove a few leftover trailing spaces from PR #5816 --- system/libraries/Session/drivers/Session_redis_driver.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index cb6bf3645..cba8c4f1d 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -78,27 +78,27 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle /** * Name of setTimeout() method in phpRedis - * + * * Due to some deprecated methods in phpRedis, we need to call the * specific methods depending on the version of phpRedis. - * + * * @var string */ protected $_setTimeout_name; /** * Name of delete() method in phpRedis - * + * * Due to some deprecated methods in phpRedis, we need to call the * specific methods depending on the version of phpRedis. - * + * * @var string */ protected $_delete_name; /** * Success return value of ping() method in phpRedis - * + * * @var mixed */ protected $_ping_success; -- cgit v1.2.3-24-g4f1b From 6ba0207160f8f2b99c79dd285bccf45f574ec660 Mon Sep 17 00:00:00 2001 From: sapics Date: Wed, 24 Jun 2020 11:51:36 +0900 Subject: Fix user guide url Replace from https://codeigniter.com/user_guide/* to https://codeigniter.com/userguide3/* --- system/libraries/Session/drivers/Session_redis_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index 1bbb13db5..1db02521e 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -44,7 +44,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); * @subpackage Libraries * @category Sessions * @author Andrey Andreev - * @link https://codeigniter.com/user_guide/libraries/sessions.html + * @link https://codeigniter.com/userguide3/libraries/sessions.html */ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandlerInterface { -- cgit v1.2.3-24-g4f1b From 04fa59834e4f6906f383acf13f921104d397cf96 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 5 Jan 2021 14:28:01 +0200 Subject: [ci skip] Add TLS support for Session library Redis connection strings (related: issue #5982, PR #5983) --- system/libraries/Session/drivers/Session_redis_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index 1db02521e..df99cc74a 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -137,7 +137,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle { $save_path = array('path' => $matches[1]); } - elseif (preg_match('#(?:tcp://)?([^:?]+)(?:\:(\d+))?(?\?.+)?#', $this->_config['save_path'], $matches)) + elseif (preg_match('#(?:(?:tcp|tls)://)?([^:?]+)(?:\:(\d+))?(?\?.+)?#', $this->_config['save_path'], $matches)) { $save_path = array( 'host' => $matches[1], -- cgit v1.2.3-24-g4f1b From 3efe7f0d070ad530208ea4f732708c1e660df0a7 Mon Sep 17 00:00:00 2001 From: George Petculescu Date: Sun, 26 Jun 2022 16:11:29 +0300 Subject: Fixes #6141 --- system/libraries/Session/drivers/Session_redis_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Session/drivers/Session_redis_driver.php') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index 2614aa37e..4d822d585 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -143,7 +143,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements CI_Session_dr $save_path = array( 'host' => $matches[1], 'port' => empty($matches[2]) ? NULL : $matches[2], - 'timeout' => NULL // We always pass this to Redis::connect(), so it needs to exist + 'timeout' => 0.0 // We always pass this to Redis::connect(), so it needs to exist ); } else -- cgit v1.2.3-24-g4f1b