summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authorsskaje <sskaje@gmail.com>2015-11-14 04:55:36 +0100
committerkemeng <kemeng@autohello.com>2015-11-14 04:55:36 +0100
commit874096c1f652f25b7f3e89e8c6b45b13c8a5e0e8 (patch)
tree94411b66e72848fb7592d2df949a5a2422dea5ff /system
parentad70b9988e5581229efde818715ba4a201502a39 (diff)
add unix socket support to redis session driver
Diffstat (limited to 'system')
-rw-r--r--system/libraries/Session/drivers/Session_redis_driver.php20
1 files changed, 19 insertions, 1 deletions
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.');
}