diff options
author | Robin Appelman <robin@icewind.nl> | 2024-07-22 14:25:20 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2024-07-22 14:25:20 +0200 |
commit | 32f5739bc66bda6b23e4243279fa618560b10f56 (patch) | |
tree | 7199e89726659f7f974cb40c45229280faa0b9bb | |
parent | 9c25a2b05fd2fc2f41c38acab1f895cb997f9762 (diff) | |
download | nextcloud-server-32f5739bc66bda6b23e4243279fa618560b10f56.tar.gz nextcloud-server-32f5739bc66bda6b23e4243279fa618560b10f56.zip |
feat: add config flag to toggle persistent redis connections
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r-- | lib/private/RedisFactory.php | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/lib/private/RedisFactory.php b/lib/private/RedisFactory.php index fd5078116c0..b5779cbfbaa 100644 --- a/lib/private/RedisFactory.php +++ b/lib/private/RedisFactory.php @@ -55,6 +55,7 @@ class RedisFactory { // # TLS support // # https://github.com/phpredis/phpredis/issues/1600 $connectionParameters = $this->getSslContext($config); + $persistent = $this->config->getValue('redis.persistent', true); // cluster config if ($isCluster) { @@ -64,9 +65,9 @@ class RedisFactory { // Support for older phpredis versions not supporting connectionParameters if ($connectionParameters !== null) { - $this->instance = new \RedisCluster(null, $config['seeds'], $timeout, $readTimeout, true, $auth, $connectionParameters); + $this->instance = new \RedisCluster(null, $config['seeds'], $timeout, $readTimeout, $persistent, $auth, $connectionParameters); } else { - $this->instance = new \RedisCluster(null, $config['seeds'], $timeout, $readTimeout, true, $auth); + $this->instance = new \RedisCluster(null, $config['seeds'], $timeout, $readTimeout, $persistent, $auth); } if (isset($config['failover_mode'])) { @@ -85,17 +86,25 @@ class RedisFactory { $connectionParameters = [ 'stream' => $this->getSslContext($config) ]; - /** - * even though the stubs and documentation don't want you to know this, - * pconnect does have the same $connectionParameters argument connect has - * - * https://github.com/phpredis/phpredis/blob/0264de1824b03fb2d0ad515b4d4ec019cd2dae70/redis.c#L710-L730 - * - * @psalm-suppress TooManyArguments - */ - $this->instance->pconnect($host, $port, $timeout, null, 0, $readTimeout, $connectionParameters); + if ($persistent) { + /** + * even though the stubs and documentation don't want you to know this, + * pconnect does have the same $connectionParameters argument connect has + * + * https://github.com/phpredis/phpredis/blob/0264de1824b03fb2d0ad515b4d4ec019cd2dae70/redis.c#L710-L730 + * + * @psalm-suppress TooManyArguments + */ + $this->instance->pconnect($host, $port, $timeout, null, 0, $readTimeout, $connectionParameters); + } else { + $this->instance->connect($host, $port, $timeout, null, 0, $readTimeout, $connectionParameters); + } } else { - $this->instance->pconnect($host, $port, $timeout, null, 0, $readTimeout); + if ($persistent) { + $this->instance->pconnect($host, $port, $timeout, null, 0, $readTimeout); + } else { + $this->instance->connect($host, $port, $timeout, null, 0, $readTimeout); + } } |