summaryrefslogtreecommitdiffstats
path: root/system/libraries/Session/drivers/Session_redis_driver.php
diff options
context:
space:
mode:
Diffstat (limited to 'system/libraries/Session/drivers/Session_redis_driver.php')
-rw-r--r--system/libraries/Session/drivers/Session_redis_driver.php55
1 files changed, 48 insertions, 7 deletions
diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php
index 0609fda95..930e00d53 100644
--- a/system/libraries/Session/drivers/Session_redis_driver.php
+++ b/system/libraries/Session/drivers/Session_redis_driver.php
@@ -76,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;
+
+ /**
+ * Success return value of ping() method in phpRedis
+ *
+ * @var mixed
+ */
+ protected $_ping_success;
+
// ------------------------------------------------------------------------
/**
@@ -88,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_success = TRUE;
+ }
+ else
+ {
+ $this->_setTimeout_name = 'setTimeout';
+ $this->_delete_name = 'delete';
+ $this->_ping_success = '+PONG';
+ }
+
if (empty($this->_config['save_path']))
{
log_message('error', 'Session: No Redis save path configured.');
@@ -216,7 +257,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->_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']))
@@ -229,7 +270,7 @@ 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']))
+ return ($this->_redis->{$this->_setTimeout_name}($this->_key_prefix.$session_id, $this->_config['expiration']))
? $this->_success
: $this->_failure;
}
@@ -248,7 +289,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle
if (isset($this->_redis))
{
try {
- if ($this->_redis->ping() === '+PONG')
+ if ($this->_redis->ping() === $this->_ping_success)
{
$this->_release_lock();
if ($this->_redis->close() === FALSE)
@@ -283,9 +324,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->_redis->{$this->_delete_name}($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::'.$this->_delete_name.'() expected to return 1, got '.var_export($result, TRUE).' instead.');
}
$this->_cookie_destroy();
@@ -344,7 +385,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->_redis->{$this->_setTimeout_name}($this->_lock_key, 300);
}
// 30 attempts to obtain a lock, in case another request already has it
@@ -402,7 +443,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->_redis->{$this->_delete_name}($this->_lock_key))
{
log_message('error', 'Session: Error while trying to free lock for '.$this->_lock_key);
return FALSE;