Skip to content

Commit

Permalink
Merge branch '5.6-add-missing-phpredis-parameters-to-connector' of ht…
Browse files Browse the repository at this point in the history
…tps://github.com/SkepticalHippo/framework into SkepticalHippo-5.6-add-missing-phpredis-parameters-to-connector
  • Loading branch information
taylorotwell committed Jun 30, 2018
2 parents ae8aa1c + a1fc761 commit caacc3e
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
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

0 comments on commit caacc3e

Please sign in to comment.