Skip to content

Commit e961224

Browse files
Added missing phpredis connection parameters.
1 parent 7047df2 commit e961224

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,17 @@ public function it_runs_raw_command()
573573
}
574574
}
575575

576+
/**
577+
* @test
578+
*/
579+
public function it_persists_connection()
580+
{
581+
$this->assertEquals(
582+
'laravel',
583+
$this->connections()['persistent']->getPersistentID()
584+
);
585+
}
586+
576587
public function connections()
577588
{
578589
$connections = [
@@ -595,7 +606,21 @@ public function connections()
595606
],
596607
]);
597608

609+
$persistentPhpRedis = new RedisManager('phpredis', [
610+
'cluster' => false,
611+
'default' => [
612+
'host' => $host,
613+
'port' => $port,
614+
'database' => 6,
615+
'options' => ['prefix' => 'laravel:'],
616+
'timeout' => 0.5,
617+
'persistent' => true,
618+
'persistent_id' => 'laravel'
619+
],
620+
]);
621+
598622
$connections[] = $prefixedPhpredis->connection();
623+
$connections['persistent'] = $persistentPhpRedis->connection();
599624
}
600625

601626
return $connections;

0 commit comments

Comments
 (0)