From a40d21cd00d5962923c4ae20d00c90f2ee39de69 Mon Sep 17 00:00:00 2001 From: Robert Lemke Date: Thu, 24 Nov 2022 10:00:20 +0100 Subject: [PATCH 1/2] Support comma-separated sentinels in CLI command --- Classes/Command/RedisSentinelCommandController.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Classes/Command/RedisSentinelCommandController.php b/Classes/Command/RedisSentinelCommandController.php index b2ce6bf..cdf76f2 100644 --- a/Classes/Command/RedisSentinelCommandController.php +++ b/Classes/Command/RedisSentinelCommandController.php @@ -67,7 +67,11 @@ public function listCommand(): void foreach ($redisSentinelBackends as $cacheIdentifier => $cacheConfiguration) { $host = $cacheConfiguration['backendOptions']['hostname'] ?? ''; if (isset($cacheConfiguration['backendOptions']['sentinels'])) { - $host = implode(', ', $cacheConfiguration['backendOptions']['sentinels']); + if (is_array($cacheConfiguration['backendOptions']['sentinels'])) { + $host = implode(', ', $cacheConfiguration['backendOptions']['sentinels']); + } else { + $host = $cacheConfiguration['backendOptions']['sentinels']; + } } $rows[] = [ @@ -284,7 +288,7 @@ public function connectCommand(string $cacheIdentifier): void $this->outputLine('Everything seems to work'); } - private function getRedisClient(array $sentinels, string $password, string $service, string $hostname, int $port, int $database, int $timeout, int $readWriteTimeout): Client + private function getRedisClient(array|string $sentinels, string $password, string $service, string $hostname, int $port, int $database, int $timeout, int $readWriteTimeout): Client { $options = [ 'parameters' => [ @@ -298,9 +302,10 @@ private function getRedisClient(array $sentinels, string $password, string $serv $options['parameters']['password'] = $password; } - if ($sentinels !== []) { + if ($sentinels !== [] && $sentinels !== '') { $connectionParameters = []; - foreach ($sentinels as $sentinel) { + $sentinelsArray = is_array($sentinels) ? $sentinels : explode(',', $sentinels); + foreach ($sentinelsArray as $sentinel) { $parsed = Parameters::parse($sentinel); $connectionParameters[] = [ 'host' => $parsed['host'], From 4cf723c0a7b2bc2a5fa5186645577f80c9bd3762 Mon Sep 17 00:00:00 2001 From: Robert Lemke Date: Thu, 24 Nov 2022 10:08:24 +0100 Subject: [PATCH 2/2] Detect custom backends based on Flow's MultiBackend --- Classes/Command/RedisSentinelCommandController.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Classes/Command/RedisSentinelCommandController.php b/Classes/Command/RedisSentinelCommandController.php index cdf76f2..573c4ed 100644 --- a/Classes/Command/RedisSentinelCommandController.php +++ b/Classes/Command/RedisSentinelCommandController.php @@ -53,7 +53,13 @@ public function listCommand(): void if ($cacheConfiguration['backend'] === RedisBackend::class) { $redisSentinelBackends[$cacheIdentifier] = $cacheConfiguration; $redisSentinelBackends[$cacheIdentifier]['multiCache'] = false; - } elseif ($cacheConfiguration['backend'] === MultiBackend::class || $cacheConfiguration['backend'] === TaggableMultiBackend::class || $cacheConfiguration['backend'] === IterableMultiBackend::class) { + } elseif ( + is_subclass_of($cacheConfiguration['backend'], MultiBackend::class, true) || + ( + strpos($cacheConfiguration['backend'], 'MultiBackend') !== false && + is_array($cacheConfiguration['backendOptions']['backendConfigurations']) + ) + ) { foreach ($cacheConfiguration['backendOptions']['backendConfigurations'] as $subCacheConfiguration) { if ($subCacheConfiguration['backend'] === RedisBackend::class) { $redisSentinelBackends[$cacheIdentifier] = $subCacheConfiguration; @@ -113,7 +119,10 @@ public function connectCommand(string $cacheIdentifier): void $cacheBackend = $cache->getBackend(); $backendConfiguration = $cacheConfigurations[$cacheIdentifier]['backendOptions']; - if ($cacheBackend instanceof MultiBackend) { + if ($cacheBackend instanceof MultiBackend || ( + strpos(get_class($cacheBackend), 'MultiBackend') !== false && + is_array($backendConfiguration['backendConfigurations']) + )) { $this->output('Multi Backend detected, looking up actual cache '); if (!isset($cacheConfigurations[$cacheIdentifier]['backendOptions']['backendConfigurations'])) {