summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2015-11-16 14:47:42 +0100
committerAndrey Andreev <narf@devilix.net>2015-11-16 14:47:42 +0100
commit6c0c34799dff95d2cc69e625cd7d3e88ff0a07a3 (patch)
tree42db7bd23be6bdd7ee92729c5655ba530ad97325
parent1c0ab9ed4b40587b525c6a22d1370b41993ffd5c (diff)
parente9e4ab00991343ba94f9542c1a6f18a42b559257 (diff)
Merge pull request #4240 from sskaje/develop
Add unix socket support to redis session driver
-rw-r--r--system/libraries/Session/drivers/Session_redis_driver.php50
-rw-r--r--user_guide_src/source/changelog.rst5
2 files changed, 44 insertions, 11 deletions
diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php
index b098cc441..8f9bcce24 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 (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];
+ }
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,
@@ -127,23 +141,37 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle
return FALSE;
}
+ $connected = TRUE;
$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')
{
- 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']))
- {
- log_message('error', 'Session: Unable to authenticate to Redis instance.');
+ if ( ! $redis->connect($this->_config['save_path']['path']))
+ {
+ log_message('error', 'Session: Unable to connect to Redis with the configured settings.');
+ $connected = FALSE;
+ }
}
- elseif (isset($this->_config['save_path']['database']) && ! $redis->select($this->_config['save_path']['database']))
+ elseif ( ! $redis->connect($this->_config['save_path']['host'], $this->_config['save_path']['port'], $this->_config['save_path']['timeout']))
{
- log_message('error', 'Session: Unable to select Redis database with index '.$this->_config['save_path']['database']);
+ log_message('error', 'Session: Unable to connect to Redis with the configured settings.');
+ $connected = FALSE;
}
- else
+
+ if ($connected)
{
- $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;
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 77ccd7ce7..6c11bf3d7 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -7,6 +7,11 @@ Version 3.1.0
Release Date: Not Released
+- Session
+
+ - Add unix socket support to redis session driver.
+
+
Version 3.0.4
=============