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

[5.6] Add missing phpredis connection parameters to PhpRedisConnector. #24678

Merged
Show file tree
Hide file tree
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
41 changes: 39 additions & 2 deletions src/Illuminate/Redis/Connectors/PhpRedisConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,45 @@ protected function createClient(array $config)
*/
protected function establishConnection($client, array $config)
{
$client->{($config['persistent'] ?? false) === true ? 'pconnect' : 'connect'}(
$config['host'], $config['port'], Arr::get($config, 'timeout', 0)
if ($config['persistent'] ?? false) {
$this->establishPersistentConnection($client, $config);
} else {
$this->establishRegularConnection($client, $config);
}
}

/**
* Establish a persistent connection with the Redis host.
*
* @param \Redis $client
* @param array $config
* @return void
*/
protected function establishPersistentConnection($client, array $config)
{
$client->pconnect(
$config['host'],
$config['port'],
Arr::get($config, 'timeout', 0.0),
Arr::get($config, 'persistent_id', null)
);
}

/**
* Establish a regular connection with the Redis host.
*
* @param \Redis $client
* @param array $config
* @return void
*/
protected function establishRegularConnection($client, array $config)
{
$client->connect(
$config['host'],
$config['port'],
Arr::get($config, 'timeout', 0.0),
Arr::get($config, 'reserved', null),
Arr::get($config, 'retry_interval', 0)
);
}

Expand Down
29 changes: 29 additions & 0 deletions tests/Redis/RedisConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,21 @@ public function it_runs_raw_command()
}
}

/**
* @test
*/
public function it_persists_connection()
{
if (PHP_ZTS) {
$this->markTestSkipped('PhpRedis does not support persistent connections with PHP_ZTS enabled.');
}

$this->assertEquals(
'laravel',
$this->connections()['persistent']->getPersistentID()
);
}

public function connections()
{
$connections = [
Expand All @@ -595,7 +610,21 @@ public function connections()
],
]);

$persistentPhpRedis = new RedisManager('phpredis', [
'cluster' => false,
'default' => [
'host' => $host,
'port' => $port,
'database' => 6,
'options' => ['prefix' => 'laravel:'],
'timeout' => 0.5,
'persistent' => true,
'persistent_id' => 'laravel',
],
]);

$connections[] = $prefixedPhpredis->connection();
$connections['persistent'] = $persistentPhpRedis->connection();
}

return $connections;
Expand Down