diff --git a/common/framework/drivers/cache/memcached.php b/common/framework/drivers/cache/memcached.php index 8bc4677f4..e508e7827 100644 --- a/common/framework/drivers/cache/memcached.php +++ b/common/framework/drivers/cache/memcached.php @@ -45,10 +45,17 @@ class Memcached implements \Rhymix\Framework\Drivers\CacheInterface foreach ($config as $url) { - $info = parse_url($url); - if (isset($info['host']) && isset($info['port'])) + if (starts_with('/', $url)) { - $this->_conn->addServer($info['host'], $info['port']); + $this->_conn->addServer($url, 0); + } + else + { + $info = parse_url($url); + if (isset($info['host']) && isset($info['port'])) + { + $this->_conn->addServer($info['host'], $info['port']); + } } } } @@ -107,10 +114,17 @@ class Memcached implements \Rhymix\Framework\Drivers\CacheInterface foreach ($config as $url) { - $info = parse_url($url); - if (isset($info['host']) && isset($info['port'])) + if (starts_with('/', $url)) { - $conn->addServer($info['host'], $info['port']); + $conn->addServer($url, 0); + } + else + { + $info = parse_url($url); + if (isset($info['host']) && isset($info['port'])) + { + $conn->addServer($info['host'], $info['port']); + } } } diff --git a/common/framework/drivers/cache/redis.php b/common/framework/drivers/cache/redis.php index f26b7f9a2..2c758acc9 100644 --- a/common/framework/drivers/cache/redis.php +++ b/common/framework/drivers/cache/redis.php @@ -32,21 +32,35 @@ class Redis implements \Rhymix\Framework\Drivers\CacheInterface $this->_conn = null; foreach ($config as $url) { - $info = parse_url($url); - if (isset($info['host']) && isset($info['port'])) + if (preg_match('!^(/.+)(#[0-9]+)?$!', $url, $matches)) { $this->_conn = new \Redis; - $this->_conn->connect($info['host'], $info['port'], 0.15); - if(isset($info['user']) || isset($info['pass'])) - { - $this->_conn->auth(isset($info['user']) ? $info['user'] : $info['pass']); - } - if(isset($info['path']) && $dbnum = intval(substr($info['path'], 1))) - { - $this->_conn->select($dbnum); - } + $this->_conn->connect($matches[1]); + $this->_conn->select($matches[2] ? substr($matches[2], 1) : 0); break; } + else + { + $info = parse_url($url); + if (isset($info['host']) && isset($info['port'])) + { + $this->_conn = new \Redis; + $this->_conn->connect($info['host'], $info['port'], 0.15); + if(isset($info['user']) || isset($info['pass'])) + { + $this->_conn->auth(isset($info['user']) ? $info['user'] : $info['pass']); + } + if(isset($info['fragment']) && $dbnum = intval($info['fragment'])) + { + $this->_conn->select($dbnum); + } + elseif(isset($info['path']) && $dbnum = intval(substr($info['path'], 1))) + { + $this->_conn->select($dbnum); + } + break; + } + } } } catch (\RedisException $e) @@ -97,20 +111,34 @@ class Redis implements \Rhymix\Framework\Drivers\CacheInterface $conn = new \Redis; foreach ($config as $url) { - $info = parse_url($url); - if (isset($info['host']) && isset($info['port'])) + if (preg_match('!^(/.+)(#[0-9]+)?$!', $url, $matches)) { - $conn->connect($info['host'], $info['port'], 0.15); - if(isset($info['user']) || isset($info['pass'])) - { - $conn->auth(isset($info['user']) ? $info['user'] : $info['pass']); - } - if(isset($info['path']) && $dbnum = intval(substr($info['path'], 1))) - { - $conn->select($dbnum); - } + $conn = new \Redis; + $conn->connect($matches[1]); + $conn->select($matches[2] ? substr($matches[2], 1) : 0); return true; } + else + { + $info = parse_url($url); + if (isset($info['host']) && isset($info['port'])) + { + $conn->connect($info['host'], $info['port'], 0.15); + if(isset($info['user']) || isset($info['pass'])) + { + $conn->auth(isset($info['user']) ? $info['user'] : $info['pass']); + } + if(isset($info['fragment']) && $dbnum = intval($info['fragment'])) + { + $conn->select($dbnum); + } + elseif(isset($info['path']) && $dbnum = intval(substr($info['path'], 1))) + { + $conn->select($dbnum); + } + return true; + } + } } return false; } diff --git a/modules/admin/admin.admin.controller.php b/modules/admin/admin.admin.controller.php index f6abd3364..d65a2663b 100644 --- a/modules/admin/admin.admin.controller.php +++ b/modules/admin/admin.admin.controller.php @@ -725,10 +725,18 @@ class adminAdminController extends admin { if ($vars->object_cache_type === 'memcached' || $vars->object_cache_type === 'redis') { - $cache_servers = array($vars->object_cache_type . '://' . $vars->object_cache_host . ':' . intval($vars->object_cache_port)); + if (starts_with('/', $vars->object_cache_host)) + { + $cache_servers = array($vars->object_cache_host); + } + else + { + $cache_servers = array($vars->object_cache_type . '://' . $vars->object_cache_host . ':' . intval($vars->object_cache_port)); + } + if ($vars->object_cache_type === 'redis') { - $cache_servers[0] .= '/' . intval($vars->object_cache_dbnum); + $cache_servers[0] .= '#' . intval($vars->object_cache_dbnum); } } else diff --git a/modules/admin/admin.admin.view.php b/modules/admin/admin.admin.view.php index 74c4f5c99..afde9c953 100644 --- a/modules/admin/admin.admin.view.php +++ b/modules/admin/admin.admin.view.php @@ -519,10 +519,19 @@ class adminAdminView extends admin if ($cache_servers) { - Context::set('object_cache_host', parse_url(array_first($cache_servers), PHP_URL_HOST) ?: null); - Context::set('object_cache_port', parse_url(array_first($cache_servers), PHP_URL_PORT) ?: null); - $cache_dbnum = preg_replace('/[^\d]/', '', parse_url(array_first($cache_servers), PHP_URL_PATH)); - Context::set('object_cache_dbnum', $cache_dbnum === '' ? 1 : intval($cache_dbnum)); + if (preg_match('!^(/.+)(#[0-9]+)?$!', array_first($cache_servers), $matches)) + { + Context::set('object_cache_host', $matches[1]); + Context::set('object_cache_port', 0); + Context::set('object_cache_dbnum', $matches[2] ? substr($matches[2], 1) : 0); + } + else + { + Context::set('object_cache_host', parse_url(array_first($cache_servers), PHP_URL_HOST) ?: null); + Context::set('object_cache_port', parse_url(array_first($cache_servers), PHP_URL_PORT) ?: null); + $cache_dbnum = preg_replace('/[^\d]/', '', parse_url(array_first($cache_servers), PHP_URL_FRAGMENT) ?: parse_url(array_first($cache_servers), PHP_URL_PATH)); + Context::set('object_cache_dbnum', $cache_dbnum === '' ? 1 : intval($cache_dbnum)); + } } else {