Skip to content

Commit e827b86

Browse files
Merge pull request #46684 from nextcloud/backport/46674/stable29
[stable29] feat: add config flag to toggle persistent redis connections
2 parents a80d726 + 692f4fa commit e827b86

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
@@ -74,6 +74,7 @@ private function create() {
7474
// # TLS support
7575
// # https://github.com/phpredis/phpredis/issues/1600
7676
$connectionParameters = $this->getSslContext($config);
77+
$persistent = $this->config->getValue('redis.persistent', true);
7778

7879
// cluster config
7980
if ($isCluster) {
@@ -83,9 +84,9 @@ private function create() {
8384

8485
// Support for older phpredis versions not supporting connectionParameters
8586
if ($connectionParameters !== null) {
86-
$this->instance = new \RedisCluster(null, $config['seeds'], $timeout, $readTimeout, true, $auth, $connectionParameters);
87+
$this->instance = new \RedisCluster(null, $config['seeds'], $timeout, $readTimeout, $persistent, $auth, $connectionParameters);
8788
} else {
88-
$this->instance = new \RedisCluster(null, $config['seeds'], $timeout, $readTimeout, true, $auth);
89+
$this->instance = new \RedisCluster(null, $config['seeds'], $timeout, $readTimeout, $persistent, $auth);
8990
}
9091

9192
if (isset($config['failover_mode'])) {
@@ -104,17 +105,25 @@ private function create() {
104105
$connectionParameters = [
105106
'stream' => $this->getSslContext($config)
106107
];
107-
/**
108-
* even though the stubs and documentation don't want you to know this,
109-
* pconnect does have the same $connectionParameters argument connect has
110-
*
111-
* https://github.com/phpredis/phpredis/blob/0264de1824b03fb2d0ad515b4d4ec019cd2dae70/redis.c#L710-L730
112-
*
113-
* @psalm-suppress TooManyArguments
114-
*/
115-
$this->instance->pconnect($host, $port, $timeout, null, 0, $readTimeout, $connectionParameters);
108+
if ($persistent) {
109+
/**
110+
* even though the stubs and documentation don't want you to know this,
111+
* pconnect does have the same $connectionParameters argument connect has
112+
*
113+
* https://github.com/phpredis/phpredis/blob/0264de1824b03fb2d0ad515b4d4ec019cd2dae70/redis.c#L710-L730
114+
*
115+
* @psalm-suppress TooManyArguments
116+
*/
117+
$this->instance->pconnect($host, $port, $timeout, null, 0, $readTimeout, $connectionParameters);
118+
} else {
119+
$this->instance->connect($host, $port, $timeout, null, 0, $readTimeout, $connectionParameters);
120+
}
116121
} else {
117-
$this->instance->pconnect($host, $port, $timeout, null, 0, $readTimeout);
122+
if ($persistent) {
123+
$this->instance->pconnect($host, $port, $timeout, null, 0, $readTimeout);
124+
} else {
125+
$this->instance->connect($host, $port, $timeout, null, 0, $readTimeout);
126+
}
118127
}
119128

120129

0 commit comments

Comments
 (0)