diff --git a/src/Connectors/PhpRedisSentinelConnector.php b/src/Connectors/PhpRedisSentinelConnector.php index 4face14..89dca10 100644 --- a/src/Connectors/PhpRedisSentinelConnector.php +++ b/src/Connectors/PhpRedisSentinelConnector.php @@ -58,11 +58,7 @@ protected function createClient(array $config): Redis $master = $sentinel->master($service); - if ($master === false - || ! is_array($master) - || ! isset($master['ip']) - || ! isset($master['port']) - ) { + if (! $this->isValidMaster($master)) { throw new RedisException(sprintf("No master found for service '%s'.", $service)); } @@ -72,6 +68,14 @@ protected function createClient(array $config): Redis ])); } + /** + * Check whether master is valid or not. + */ + protected function isValidMaster(mixed $master): bool + { + return is_array($master) && isset($master['ip']) && isset($master['port']); + } + /** * Connect to the configured Redis Sentinel instance. *