From ef57c03dd22115ddee75c14c3c5073d924cca23a Mon Sep 17 00:00:00 2001 From: Robin McCorkell Date: Sun, 13 Mar 2016 22:41:04 +0000 Subject: Add Redis Cluster support Signed-off-by: Morris Jobke --- lib/private/RedisFactory.php | 60 +++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 23 deletions(-) (limited to 'lib/private/RedisFactory.php') diff --git a/lib/private/RedisFactory.php b/lib/private/RedisFactory.php index 3ba637c4142..e254d36aa06 100644 --- a/lib/private/RedisFactory.php +++ b/lib/private/RedisFactory.php @@ -39,32 +39,46 @@ class RedisFactory { } private function create() { - $this->instance = new \Redis(); - // TODO allow configuring a RedisArray, see https://github.com/nicolasff/phpredis/blob/master/arrays.markdown#redis-arrays - $config = $this->config->getValue('redis', array()); - if (isset($config['host'])) { - $host = $config['host']; - } else { - $host = '127.0.0.1'; - } - if (isset($config['port'])) { - $port = $config['port']; - } else { - $port = 6379; - } - if (isset($config['timeout'])) { - $timeout = $config['timeout']; + if ($config = $this->config->getValue('redis.cluster', [])) { + if (!class_exists('RedisCluster')) { + throw new \Exception('Redis Cluster support is not available'); + } + // cluster config + $timeout = isset($config['timeout']) ? $config['timeout'] : null; + $readTimeout = isset($config['read_timeout']) ? $config['read_timeout'] : null; + $this->instance = new \RedisCluster(null, $config['seeds'], $timeout, $readTimeout); + + if (isset($config['failover_mode'])) { + $this->instance->setOption(\RedisCluster::OPT_FAILOVER, $config['failover_mode']); + } } else { - $timeout = 0.0; // unlimited - } - $this->instance->connect($host, $port, $timeout); - if (isset($config['password']) && $config['password'] !== '') { - $this->instance->auth($config['password']); - } + $this->instance = new \Redis(); + $config = $this->config->getValue('redis', []); + if (isset($config['host'])) { + $host = $config['host']; + } else { + $host = '127.0.0.1'; + } + if (isset($config['port'])) { + $port = $config['port']; + } else { + $port = 6379; + } + if (isset($config['timeout'])) { + $timeout = $config['timeout']; + } else { + $timeout = 0.0; // unlimited + } + + $this->instance->connect($host, $port, $timeout); + if (isset($config['password']) && $config['password'] !== '') { + $this->instance->auth($config['password']); + } - if (isset($config['dbindex'])) { - $this->instance->select($config['dbindex']); + if (isset($config['dbindex'])) { + $this->instance->select($config['dbindex']); + } } } -- cgit v1.2.3