Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable28] feat: add config flag to toggle persistent redis connections #46683

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions lib/private/RedisFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ private function create() {
// # TLS support
// # https://github.com/phpredis/phpredis/issues/1600
$connectionParameters = $this->getSslContext($config);
$persistent = $this->config->getValue('redis.persistent', true);

// cluster config
if ($isCluster) {
Expand All @@ -83,9 +84,9 @@ private function create() {

// 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'])) {
Expand All @@ -104,17 +105,25 @@ private function create() {
$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);
}
}


Expand Down
Loading