Skip to content

Commit

Permalink
Allow passing custom commands to Predis 2.x client options
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Feb 3, 2023
1 parent dc5f443 commit 631d392
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/DependencyInjection/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ private function addClientsSection(ArrayNodeDefinition $rootNode): void
->arrayNode('options')
->addDefaultsIfNotSet()
->children()
->arrayNode('commands')
->useAttributeAsKey('name')
->scalarPrototype()->end()
->end()
->booleanNode('connection_async')->defaultFalse()->end()
->booleanNode('connection_persistent')->defaultFalse()->end()
->scalarNode('connection_timeout')->cannotBeEmpty()->defaultValue(5)->end()
Expand Down
2 changes: 2 additions & 0 deletions src/DependencyInjection/SncRedisExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ private function loadPhpredisClient(array $options, ContainerBuilder $container)
sprintf('snc_redis.%s_%sclient.class', $options['type'], ($hasClusterOption ? 'cluster' : '')),
);

unset($options['options']['commands']);

$phpredisDef = new Definition($phpredisClientClass, [
$hasSentinelOption ? RedisSentinel::class : $phpredisClientClass,
array_map('strval', $options['dsns']),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ snc_redis:
options:
parameters:
ssl_context: {'verify_peer': false, 'allow_self_signed': true, 'verify_peer_name': false}
commands:
foo: 'Foo\Bar\Baz'
35 changes: 35 additions & 0 deletions tests/DependencyInjection/SncRedisExtensionEnvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,41 @@ public function testPredisDefaultParameterWithSSLContextConfigLoad(): void
);
}

public function testPredisDefaultParameterConfig(): void
{
$container = $this->getConfiguredContainer('env_predis_ssl_context');

$clientDefinition = $container->findDefinition('snc_redis.default');

$this->assertSame('Predis\Client', $clientDefinition->getClass());
$this->assertSame(
[
'parameters' => [
'database' => null,
'username' => null,
'password' => null,
'logging' => false,
],
'commands' => ['foo' => 'Foo\Bar\Baz'],
'read_write_timeout' => null,
'iterable_multibulk' => false,
'serialization' => 'default',
'prefix' => null,
'service' => null,
'async_connect' => false,
'timeout' => 5,
'persistent' => false,
'exceptions' => true,
'ssl' => [
'verify_peer' => false,
'allow_self_signed' => true,
'verify_peer_name' => false,
],
],
$container->findDefinition((string) $clientDefinition->getArgument(1))->getArgument(0),
);
}

/**
* @testWith ["env_phpredis_minimal", "Redis"]
* ["env_relay_minimal", "Relay\\Relay"]
Expand Down

0 comments on commit 631d392

Please sign in to comment.