Skip to content

Commit 7e436fb

Browse files
committed
Fix phpredis 6.0.0-dev compatibility
This breaks sentinel's constructor phpredis/phpredis#2327
1 parent 5a26333 commit 7e436fb

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

Diff for: src/Factory/PhpredisClientFactory.php

+18-8
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,18 @@
2424
use function array_key_exists;
2525
use function array_keys;
2626
use function array_map;
27+
use function array_values;
2728
use function count;
2829
use function get_class;
2930
use function implode;
3031
use function in_array;
3132
use function is_a;
3233
use function is_array;
34+
use function phpversion;
3335
use function spl_autoload_register;
3436
use function sprintf;
3537
use function var_export;
38+
use function version_compare;
3639

3740
/** @internal */
3841
class PhpredisClientFactory
@@ -120,15 +123,22 @@ private function createClientFromSentinel(string $class, array $dsns, string $al
120123
$readTimeout = $options['read_write_timeout'] ?? 0;
121124

122125
foreach ($dsns as $dsn) {
126+
$args = [
127+
'host' => $dsn->getHost(),
128+
'port' => (int) $dsn->getPort(),
129+
'connectTimeout' => $connectionTimeout,
130+
'persistent' => $connectionPersistent,
131+
'retryInterval' => 5,
132+
'readTimeout' => $readTimeout,
133+
];
123134
try {
124-
$address = (new $sentinelClass(
125-
$dsn->getHost(),
126-
(int) $dsn->getPort(),
127-
$connectionTimeout,
128-
$connectionPersistent,
129-
5, // retry interval
130-
$readTimeout,
131-
))->getMasterAddrByName($masterName);
135+
if ($isRelay || version_compare(phpversion('redis'), '6.0', '<')) {
136+
$sentinel = new $sentinelClass(...array_values($args));
137+
} else {
138+
$sentinel = new $sentinelClass($args);
139+
}
140+
141+
$address = $sentinel->getMasterAddrByName($masterName);
132142
} catch (RedisException | RelayException $e) {
133143
continue;
134144
}

0 commit comments

Comments
 (0)