diff options
author | Robin McCorkell <robin@mccorkell.me.uk> | 2016-03-13 22:41:04 +0000 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2017-03-25 21:25:27 -0600 |
commit | ef57c03dd22115ddee75c14c3c5073d924cca23a (patch) | |
tree | 4a22243968dd6fedc6640948d50489dbaced38fe /lib/private/RedisFactory.php | |
parent | 0981f9a18a7253f7a5e7f44359c3bfc5ffe0f650 (diff) | |
download | nextcloud-server-ef57c03dd22115ddee75c14c3c5073d924cca23a.tar.gz nextcloud-server-ef57c03dd22115ddee75c14c3c5073d924cca23a.zip |
Add Redis Cluster support
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'lib/private/RedisFactory.php')
-rw-r--r-- | lib/private/RedisFactory.php | 60 |
1 files changed, 37 insertions, 23 deletions
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']); + } } } |