Skip to content

Commit

Permalink
[5.6] Refactor PhpRedis connector (#24824)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
tillkruss authored and taylorotwell committed Jul 13, 2018
1 parent ca6d6f2 commit 8af242b
Showing 1 changed file with 10 additions and 33 deletions.
43 changes: 10 additions & 33 deletions src/Illuminate/Redis/Connectors/PhpRedisConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,44 +92,21 @@ protected function createClient(array $config)
*/
protected function establishConnection($client, array $config)
{
($config['persistent'] ?? false)
? $this->establishPersistentConnection($client, $config)
: $this->establishRegularConnection($client, $config);
}
$persistent = $config['persistent'] ?? false;

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

/**
* 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)
);
if (version_compare(phpversion('redis'), '3.1.3', '>=')) {
$parameters[] = Arr::get($config, 'read_timeout', 0.0);
}

$client->{($persistent ? 'pconnect' : 'connect')}(...$parameters);
}

/**
Expand Down

0 comments on commit 8af242b

Please sign in to comment.