Skip to content

Commit 1768bd6

Browse files
authored
Merge pull request #46674 from nextcloud/redis-persist-option
feat: add config flag to toggle persistent redis connections
2 parents 9c25a2b + 32f5739 commit 1768bd6

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

lib/private/RedisFactory.php

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ private function create() {
5555
// # TLS support
5656
// # https://github.com/phpredis/phpredis/issues/1600
5757
$connectionParameters = $this->getSslContext($config);
58+
$persistent = $this->config->getValue('redis.persistent', true);
5859

5960
// cluster config
6061
if ($isCluster) {
@@ -64,9 +65,9 @@ private function create() {
6465

6566
// Support for older phpredis versions not supporting connectionParameters
6667
if ($connectionParameters !== null) {
67-
$this->instance = new \RedisCluster(null, $config['seeds'], $timeout, $readTimeout, true, $auth, $connectionParameters);
68+
$this->instance = new \RedisCluster(null, $config['seeds'], $timeout, $readTimeout, $persistent, $auth, $connectionParameters);
6869
} else {
69-
$this->instance = new \RedisCluster(null, $config['seeds'], $timeout, $readTimeout, true, $auth);
70+
$this->instance = new \RedisCluster(null, $config['seeds'], $timeout, $readTimeout, $persistent, $auth);
7071
}
7172

7273
if (isset($config['failover_mode'])) {
@@ -85,17 +86,25 @@ private function create() {
8586
$connectionParameters = [
8687
'stream' => $this->getSslContext($config)
8788
];
88-
/**
89-
* even though the stubs and documentation don't want you to know this,
90-
* pconnect does have the same $connectionParameters argument connect has
91-
*
92-
* https://github.com/phpredis/phpredis/blob/0264de1824b03fb2d0ad515b4d4ec019cd2dae70/redis.c#L710-L730
93-
*
94-
* @psalm-suppress TooManyArguments
95-
*/
96-
$this->instance->pconnect($host, $port, $timeout, null, 0, $readTimeout, $connectionParameters);
89+
if ($persistent) {
90+
/**
91+
* even though the stubs and documentation don't want you to know this,
92+
* pconnect does have the same $connectionParameters argument connect has
93+
*
94+
* https://github.com/phpredis/phpredis/blob/0264de1824b03fb2d0ad515b4d4ec019cd2dae70/redis.c#L710-L730
95+
*
96+
* @psalm-suppress TooManyArguments
97+
*/
98+
$this->instance->pconnect($host, $port, $timeout, null, 0, $readTimeout, $connectionParameters);
99+
} else {
100+
$this->instance->connect($host, $port, $timeout, null, 0, $readTimeout, $connectionParameters);
101+
}
97102
} else {
98-
$this->instance->pconnect($host, $port, $timeout, null, 0, $readTimeout);
103+
if ($persistent) {
104+
$this->instance->pconnect($host, $port, $timeout, null, 0, $readTimeout);
105+
} else {
106+
$this->instance->connect($host, $port, $timeout, null, 0, $readTimeout);
107+
}
99108
}
100109

101110

0 commit comments

Comments
 (0)