Skip to content

Commit

Permalink
[7.x] Add support for PhpRedis 5.3 options parameter (#33799)
Browse files Browse the repository at this point in the history
* fix indentation

* add `context` support for PhpRedis
  • Loading branch information
tillkruss committed Aug 11, 2020
1 parent 44c32a2 commit 76b175d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Illuminate/Redis/Connectors/PhpRedisConnector.php
Expand Up @@ -74,9 +74,9 @@ protected function createClient(array $config)
return tap(new Redis, function ($client) use ($config) {
if ($client instanceof RedisFacade) {
throw new LogicException(
extension_loaded('redis')
? 'Please remove or rename the Redis facade alias in your "app" configuration file in order to avoid collision with the PHP Redis extension.'
: 'Please make sure the PHP Redis extension is installed and enabled.'
extension_loaded('redis')
? 'Please remove or rename the Redis facade alias in your "app" configuration file in order to avoid collision with the PHP Redis extension.'
: 'Please make sure the PHP Redis extension is installed and enabled.'
);
}

Expand Down Expand Up @@ -127,6 +127,10 @@ protected function establishConnection($client, array $config)
$parameters[] = Arr::get($config, 'read_timeout', 0.0);
}

if (version_compare(phpversion('redis'), '5.3.0', '>=')) {
$parameters[] = Arr::get($config, 'context', []);
}

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

Expand All @@ -151,6 +155,10 @@ protected function createRedisClusterInstance(array $servers, array $options)
$parameters[] = $options['password'] ?? null;
}

if (version_compare(phpversion('redis'), '5.3.2', '>=')) {
$parameters[] = Arr::get($options, 'context', []);
}

return tap(new RedisCluster(...$parameters), function ($client) use ($options) {
if (! empty($options['prefix'])) {
$client->setOption(RedisCluster::OPT_PREFIX, $options['prefix']);
Expand Down

0 comments on commit 76b175d

Please sign in to comment.