summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonty Sewell <jontysewell@gmail.com>2016-02-05 10:39:05 +0100
committerJonty Sewell <jontysewell@gmail.com>2016-02-05 10:39:05 +0100
commit74f846890d69e6f5ff5f0bb4268539803242d015 (patch)
treeba9ba009016d2e2b4dfb23e99c0a31382e510c14
parent880036d5cea0021258c43c0d0fba0e6fd9d04b69 (diff)
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 <jontysewell@gmail.com>
-rw-r--r--system/libraries/Session/drivers/Session_redis_driver.php19
1 files changed, 17 insertions, 2 deletions
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']))
{