Skip to content

Commit

Permalink
Merge pull request #28 from flownative/cli-improvements
Browse files Browse the repository at this point in the history
Auto-detect custom multi backends
  • Loading branch information
robertlemke authored Nov 24, 2022
2 parents 43f921a + 4cf723c commit fcf658d
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions Classes/Command/RedisSentinelCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -67,7 +73,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[] = [
Expand Down Expand Up @@ -109,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'])) {
Expand Down Expand Up @@ -284,7 +297,7 @@ public function connectCommand(string $cacheIdentifier): void
$this->outputLine('<success>Everything seems to work</success>');
}

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' => [
Expand All @@ -298,9 +311,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'],
Expand Down

0 comments on commit fcf658d

Please sign in to comment.