|
|
|
@ -83,8 +83,8 @@ class rcube_cache_redis extends rcube_cache
|
|
|
|
|
true, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$rcube = rcube::get_instance();
|
|
|
|
|
$hosts = $rcube->config->get('redis_hosts');
|
|
|
|
|
$rcube = rcube::get_instance();
|
|
|
|
|
$hosts = $rcube->config->get('redis_hosts');
|
|
|
|
|
|
|
|
|
|
// host config is wrong
|
|
|
|
|
if (!is_array($hosts) || empty($hosts)) {
|
|
|
|
@ -116,54 +116,56 @@ class rcube_cache_redis extends rcube_cache
|
|
|
|
|
// explode individual fields
|
|
|
|
|
list($host, $port, $database, $password) = array_pad(explode(':', $redis_host, 4), 4, null);
|
|
|
|
|
|
|
|
|
|
$params = parse_url($redis_host);
|
|
|
|
|
if ($params['scheme'] == 'redis') {
|
|
|
|
|
$host = (isset($params['host'])) ? $params['host'] : null;
|
|
|
|
|
$port = (isset($params['port'])) ? $params['port'] : null;
|
|
|
|
|
$database = (isset($params['database'])) ? $params['database'] : null;
|
|
|
|
|
$password = (isset($params['password'])) ? $params['password'] : null;
|
|
|
|
|
if (substr($redis_host, 0, 7) === 'unix://') {
|
|
|
|
|
$host = substr($port, 2);
|
|
|
|
|
$port = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// set default values if not set
|
|
|
|
|
$host = ($host !== null) ? $host : '127.0.0.1';
|
|
|
|
|
$port = ($port !== null) ? $port : 6379;
|
|
|
|
|
$database = ($database !== null) ? $database : 0;
|
|
|
|
|
|
|
|
|
|
if (self::$redis->connect($host, $port) === false) {
|
|
|
|
|
rcube::raise_error(array(
|
|
|
|
|
'code' => 604,
|
|
|
|
|
'type' => 'redis',
|
|
|
|
|
'line' => __LINE__,
|
|
|
|
|
'file' => __FILE__,
|
|
|
|
|
'message' => "Could not connect to Redis server. Please check host and port"
|
|
|
|
|
),
|
|
|
|
|
true, true);
|
|
|
|
|
else {
|
|
|
|
|
// set default values if not set
|
|
|
|
|
$host = $host ?: '127.0.0.1';
|
|
|
|
|
$port = $port ?: 6379;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($password != null && self::$redis->auth($password) === false) {
|
|
|
|
|
rcube::raise_error(array(
|
|
|
|
|
'code' => 604,
|
|
|
|
|
'type' => 'redis',
|
|
|
|
|
'line' => __LINE__,
|
|
|
|
|
'file' => __FILE__,
|
|
|
|
|
'message' => "Could not authenticate with Redis server. Please check password."
|
|
|
|
|
),
|
|
|
|
|
true, true);
|
|
|
|
|
try {
|
|
|
|
|
if (self::$redis->connect($host, $port) === false) {
|
|
|
|
|
rcube::raise_error(array(
|
|
|
|
|
'code' => 604,
|
|
|
|
|
'type' => 'redis',
|
|
|
|
|
'line' => __LINE__,
|
|
|
|
|
'file' => __FILE__,
|
|
|
|
|
'message' => "Could not connect to Redis server. Please check host and port"
|
|
|
|
|
),
|
|
|
|
|
true, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($password !== null && self::$redis->auth($password) === false) {
|
|
|
|
|
rcube::raise_error(array(
|
|
|
|
|
'code' => 604,
|
|
|
|
|
'type' => 'redis',
|
|
|
|
|
'line' => __LINE__,
|
|
|
|
|
'file' => __FILE__,
|
|
|
|
|
'message' => "Could not authenticate with Redis server. Please check password."
|
|
|
|
|
),
|
|
|
|
|
true, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($database !== null && self::$redis->select($database) === false) {
|
|
|
|
|
rcube::raise_error(array(
|
|
|
|
|
'code' => 604,
|
|
|
|
|
'type' => 'redis',
|
|
|
|
|
'line' => __LINE__,
|
|
|
|
|
'file' => __FILE__,
|
|
|
|
|
'message' => "Could not select Redis database. Please check database setting."
|
|
|
|
|
),
|
|
|
|
|
true, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($database != 0 && self::$redis->select($database) === false) {
|
|
|
|
|
rcube::raise_error(array(
|
|
|
|
|
'code' => 604,
|
|
|
|
|
'type' => 'redis',
|
|
|
|
|
'line' => __LINE__,
|
|
|
|
|
'file' => __FILE__,
|
|
|
|
|
'message' => "Could not select Redis database. Please check database setting."
|
|
|
|
|
),
|
|
|
|
|
true, true);
|
|
|
|
|
catch (Exception $e) {
|
|
|
|
|
rcube::raise_error($e, true, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (self::$redis->ping() != "+PONG") {
|
|
|
|
|
if (self::$redis->ping() !== "+PONG") {
|
|
|
|
|
self::$redis = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|