Skip to content

Commit

Permalink
Fix predis compatibility in non-replicated setups
Browse files Browse the repository at this point in the history
  • Loading branch information
ostrolucky committed Dec 10, 2022
1 parent 6f654e4 commit 9e6b111
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private function addClientsSection(ArrayNodeDefinition $rootNode): void
->scalarNode('profile')->defaultValue('default')->end()
->scalarNode('cluster')->defaultNull()->end()
->scalarNode('prefix')->defaultNull()->end()
->enumNode('replication')->values([true, false, 'sentinel'])->defaultValue(false)->end()
->enumNode('replication')->values([true, 'sentinel'])->end()
->scalarNode('service')->defaultNull()->end()
->enumNode('slave_failover')->values(['none', 'error', 'distribute', 'distribute_slaves'])->end()
->arrayNode('parameters')
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/SncRedisExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private function loadPredisClient(array $client, ContainerBuilder $container): v
$container->setDefinition($optionId, $optionDef);
$clientDef = new Definition((string) $container->getParameter('snc_redis.client.class'));
$clientDef->addTag('snc_redis.client', ['alias' => $client['alias']]);
if ($connectionCount === 1 && !isset($client['options']['cluster']) && !isset($client['options']['replication'])) {
if ($connectionCount === 1 && !isset($client['options']['cluster'], $client['options']['replication'])) {
$clientDef->addArgument(new Reference(sprintf('snc_redis.connection.%s_parameters.%s', $connectionAliases[0], $client['alias'])));
} else {
$connections = [];
Expand Down Expand Up @@ -228,7 +228,7 @@ private function loadPhpredisClient(array $options, ContainerBuilder $container)
{
$connectionCount = count($options['dsns']);
$hasClusterOption = $options['options']['cluster'] !== null;
$hasSentinelOption = (bool) $options['options']['replication'];
$hasSentinelOption = isset($options['options']['replication']);

if ($connectionCount > 1 && !$hasClusterOption && !$hasSentinelOption) {
throw new LogicException('Use options "cluster" or "sentinel" to enable support for multi DSN instances.');
Expand Down
5 changes: 0 additions & 5 deletions tests/DependencyInjection/SncRedisExtensionEnvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public function testPhpredisDefaultParameterConfig(): void
'profile' => 'default',
'cluster' => null,
'prefix' => null,
'replication' => false,
'service' => null,
],
$clientDefinition->getArgument(2),
Expand Down Expand Up @@ -104,7 +103,6 @@ public function testPhpredisFullConfig(): void
'throw_errors' => true,
'profile' => 'default',
'cluster' => null,
'replication' => false,
'service' => null,
],
$clientDefinition->getArgument(2),
Expand Down Expand Up @@ -143,7 +141,6 @@ public function testPhpredisWithAclConfig(): void
'serialization' => 'php',
'service' => null,
'throw_errors' => true,
'replication' => null,
],
$clientDefinition->getArgument(2),
);
Expand Down Expand Up @@ -196,7 +193,6 @@ public function testPhpRedisClusterOption(): void
'serialization' => 'default',
'profile' => 'default',
'prefix' => null,
'replication' => false,
'service' => null,
],
$clientDefinition->getArgument(2),
Expand Down Expand Up @@ -257,7 +253,6 @@ public function testPhpRedisClusterOptionMultipleDsn(): void
'serialization' => 'default',
'profile' => 'default',
'prefix' => null,
'replication' => false,
'service' => null,
],
$clientDefinition->getArgument(2),
Expand Down
4 changes: 2 additions & 2 deletions tests/DependencyInjection/SncRedisExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ public function testSingleSentinelOption(): void
$this->assertEquals('sentinel', $options['replication']);
$this->assertEquals('mymaster', $options['service']);
$parameters = $container->getDefinition('snc_redis.default')->getArgument(0);
$this->assertEquals('snc_redis.connection.default_parameters.default', (string) $parameters[0]);
$masterParameters = $container->getDefinition((string) $parameters[0])->getArgument(0);
$this->assertEquals('snc_redis.connection.default_parameters.default', (string) $parameters);
$masterParameters = $container->getDefinition((string) $parameters)->getArgument(0);
$this->assertEquals('sentinel', $masterParameters['replication']);
$this->assertEquals('mymaster', $masterParameters['service']);
$this->assertIsArray($masterParameters['parameters']);
Expand Down

0 comments on commit 9e6b111

Please sign in to comment.