Skip to content

Commit

Permalink
[ci skip] Polish changes from PR bcit-ci#4240
Browse files Browse the repository at this point in the history
  • Loading branch information
narfbg committed Nov 16, 2015
1 parent 6c0c347 commit 0f6e5bc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 40 deletions.
71 changes: 33 additions & 38 deletions system/libraries/Session/drivers/Session_redis_driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,41 +85,39 @@ public function __construct(&$params)
{
log_message('error', 'Session: No Redis save path configured.');
}
elseif (preg_match('#^unix://([^\?]+)(\?.+)?$#', $this->_config['save_path'], $matches))
elseif (preg_match('#^unix://([^\?]+)(?<options>\?.+)?$#', $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];
$save_path = array('path' => $matches[1]);
}
elseif (preg_match('#(?:tcp://)?([^:?]+)(?:\:(\d+))?(\?.+)?#', $this->_config['save_path'], $matches))
elseif (preg_match('#(?:tcp://)?([^:?]+)(?:\:(\d+))?(?<options>\?.+)?#', $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',
$save_path = array(
'host' => $matches[1],
'port' => empty($matches[2]) ? NULL : $matches[2],
'password' => preg_match('#auth=([^\s&]+)#', $matches[3], $match) ? $match[1] : NULL,
'database' => preg_match('#database=(\d+)#', $matches[3], $match) ? (int) $match[1] : NULL,
'timeout' => preg_match('#timeout=(\d+\.\d+)#', $matches[3], $match) ? (float) $match[1] : NULL
'port' => empty($matches[2]) ? NULL : $matches[2]
);

preg_match('#prefix=([^\s&]+)#', $matches[3], $match) && $this->_key_prefix = $match[1];
}
else
{
log_message('error', 'Session: Invalid Redis save path format: '.$this->_config['save_path']);
}

if ($this->_config['match_ip'] === TRUE)
if (isset($save_path))
{
$this->_key_prefix .= $_SERVER['REMOTE_ADDR'].':';
if (isset($matches['options']))
{
$save_path['password'] = preg_match('#auth=([^\s&]+)#', $matches['options'], $match) ? $match[1] : NULL;
$save_path['database'] = preg_match('#database=(\d+)#', $matches['options'], $match) ? (int) $match[1] : NULL;
$save_path['timeout'] = preg_match('#timeout=(\d+\.\d+)#', $matches['options'], $match) ? (float) $match[1] : NULL;

preg_match('#prefix=([^\s&]+)#', $matches['options'], $match) && $this->_key_prefix = $match[1];
}

$this->_config['save_path'] = $save_path;

if ($this->_config['match_ip'] === TRUE)
{
$this->_key_prefix .= $_SERVER['REMOTE_ADDR'].':';
}
}
}

Expand All @@ -141,23 +139,16 @@ public function open($save_path, $name)
return FALSE;
}

$connected = TRUE;
$redis = new Redis();
if ($this->_config['save_path']['type'] == 'unix')
{
if ( ! $redis->connect($this->_config['save_path']['path']))
{
log_message('error', 'Session: Unable to connect to Redis with the configured settings.');
$connected = FALSE;
}
}
elseif ( ! $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.');
$connected = FALSE;
}
$connected = isset($this->_config['save_path']['path'])
? $redis->connect($this->_config['save_path']['path'])
: $redis->connect(
$this->_config['save_path']['host'],
$this->_config['save_path']['port'],
$this->_config['save_path']['timeout']
);

if ($connected)
if ($connected)
{
if (isset($this->_config['save_path']['password']) && ! $redis->auth($this->_config['save_path']['password']))
{
Expand All @@ -173,6 +164,10 @@ public function open($save_path, $name)
return TRUE;
}
}
else
{
log_message('error', 'Session: Unable to connect to Redis with the configured settings.');
}

return FALSE;
}
Expand Down
4 changes: 2 additions & 2 deletions user_guide_src/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Version 3.1.0

Release Date: Not Released

- Session
- Libraries

- Add unix socket support to redis session driver.
- Added UNIX socket connection support to :doc:`Session Library <libraries/sessions>` 'redis' driver.


Version 3.0.4
Expand Down

0 comments on commit 0f6e5bc

Please sign in to comment.