Skip to content

Commit 8af242b

Browse files
tillkrusstaylorotwell
authored andcommitted
[5.6] Refactor PhpRedis connector (#24824)
* fix PhpRedis connector * simpify PhpRedis’s establishConnection() method connect() and pconnect() just pass through their arguments to redis_connect() * check PhpRedis version to avoid exceptions
1 parent ca6d6f2 commit 8af242b

File tree

1 file changed

+10
-33
lines changed

1 file changed

+10
-33
lines changed

src/Illuminate/Redis/Connectors/PhpRedisConnector.php

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -92,44 +92,21 @@ protected function createClient(array $config)
9292
*/
9393
protected function establishConnection($client, array $config)
9494
{
95-
($config['persistent'] ?? false)
96-
? $this->establishPersistentConnection($client, $config)
97-
: $this->establishRegularConnection($client, $config);
98-
}
95+
$persistent = $config['persistent'] ?? false;
9996

100-
/**
101-
* Establish a persistent connection with the Redis host.
102-
*
103-
* @param \Redis $client
104-
* @param array $config
105-
* @return void
106-
*/
107-
protected function establishPersistentConnection($client, array $config)
108-
{
109-
$client->pconnect(
97+
$parameters = [
11098
$config['host'],
11199
$config['port'],
112100
Arr::get($config, 'timeout', 0.0),
113-
Arr::get($config, 'persistent_id', null)
114-
);
115-
}
101+
$persistent ? Arr::get($config, 'persistent_id', null) : null,
102+
Arr::get($config, 'retry_interval', 0),
103+
];
116104

117-
/**
118-
* Establish a regular connection with the Redis host.
119-
*
120-
* @param \Redis $client
121-
* @param array $config
122-
* @return void
123-
*/
124-
protected function establishRegularConnection($client, array $config)
125-
{
126-
$client->connect(
127-
$config['host'],
128-
$config['port'],
129-
Arr::get($config, 'timeout', 0.0),
130-
Arr::get($config, 'reserved', null),
131-
Arr::get($config, 'retry_interval', 0)
132-
);
105+
if (version_compare(phpversion('redis'), '3.1.3', '>=')) {
106+
$parameters[] = Arr::get($config, 'read_timeout', 0.0);
107+
}
108+
109+
$client->{($persistent ? 'pconnect' : 'connect')}(...$parameters);
133110
}
134111

135112
/**

0 commit comments

Comments
 (0)