Skip to content

Commit caacc3e

Browse files
committed
Merge branch '5.6-add-missing-phpredis-parameters-to-connector' of https://github.com/SkepticalHippo/framework into SkepticalHippo-5.6-add-missing-phpredis-parameters-to-connector
2 parents ae8aa1c + a1fc761 commit caacc3e

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

src/Illuminate/Redis/Connectors/PhpRedisConnector.php

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,45 @@ protected function createClient(array $config)
9292
*/
9393
protected function establishConnection($client, array $config)
9494
{
95-
$client->{($config['persistent'] ?? false) === true ? 'pconnect' : 'connect'}(
96-
$config['host'], $config['port'], Arr::get($config, 'timeout', 0)
95+
if ($config['persistent'] ?? false) {
96+
$this->establishPersistentConnection($client, $config);
97+
} else {
98+
$this->establishRegularConnection($client, $config);
99+
}
100+
}
101+
102+
/**
103+
* Establish a persistent connection with the Redis host.
104+
*
105+
* @param \Redis $client
106+
* @param array $config
107+
* @return void
108+
*/
109+
protected function establishPersistentConnection($client, array $config)
110+
{
111+
$client->pconnect(
112+
$config['host'],
113+
$config['port'],
114+
Arr::get($config, 'timeout', 0.0),
115+
Arr::get($config, 'persistent_id', null)
116+
);
117+
}
118+
119+
/**
120+
* Establish a regular connection with the Redis host.
121+
*
122+
* @param \Redis $client
123+
* @param array $config
124+
* @return void
125+
*/
126+
protected function establishRegularConnection($client, array $config)
127+
{
128+
$client->connect(
129+
$config['host'],
130+
$config['port'],
131+
Arr::get($config, 'timeout', 0.0),
132+
Arr::get($config, 'reserved', null),
133+
Arr::get($config, 'retry_interval', 0)
97134
);
98135
}
99136

tests/Redis/RedisConnectionTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,21 @@ public function it_runs_raw_command()
573573
}
574574
}
575575

576+
/**
577+
* @test
578+
*/
579+
public function it_persists_connection()
580+
{
581+
if (PHP_ZTS) {
582+
$this->markTestSkipped('PhpRedis does not support persistent connections with PHP_ZTS enabled.');
583+
}
584+
585+
$this->assertEquals(
586+
'laravel',
587+
$this->connections()['persistent']->getPersistentID()
588+
);
589+
}
590+
576591
public function connections()
577592
{
578593
$connections = [
@@ -595,7 +610,21 @@ public function connections()
595610
],
596611
]);
597612

613+
$persistentPhpRedis = new RedisManager('phpredis', [
614+
'cluster' => false,
615+
'default' => [
616+
'host' => $host,
617+
'port' => $port,
618+
'database' => 6,
619+
'options' => ['prefix' => 'laravel:'],
620+
'timeout' => 0.5,
621+
'persistent' => true,
622+
'persistent_id' => 'laravel',
623+
],
624+
]);
625+
598626
$connections[] = $prefixedPhpredis->connection();
627+
$connections['persistent'] = $persistentPhpRedis->connection();
599628
}
600629

601630
return $connections;

0 commit comments

Comments
 (0)