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