Skip to content

Commit 936ca64

Browse files
Seldaekostrolucky
authored andcommitted
Allow passing custom commands to Predis 2.x client options
1 parent 8b3d902 commit 936ca64

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

Diff for: src/DependencyInjection/Configuration/Configuration.php

+4
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ private function addClientsSection(ArrayNodeDefinition $rootNode): void
119119
->arrayNode('options')
120120
->addDefaultsIfNotSet()
121121
->children()
122+
->arrayNode('commands')
123+
->useAttributeAsKey('name')
124+
->scalarPrototype()->end()
125+
->end()
122126
->booleanNode('connection_async')->defaultFalse()->end()
123127
->booleanNode('connection_persistent')->defaultFalse()->end()
124128
->scalarNode('connection_timeout')->cannotBeEmpty()->defaultValue(5)->end()

Diff for: src/DependencyInjection/SncRedisExtension.php

+2
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ private function loadPhpredisClient(array $options, ContainerBuilder $container)
222222
sprintf('snc_redis.%s_%sclient.class', $options['type'], ($hasClusterOption ? 'cluster' : '')),
223223
);
224224

225+
unset($options['options']['commands']);
226+
225227
$phpredisDef = new Definition($phpredisClientClass, [
226228
$hasSentinelOption ? RedisSentinel::class : $phpredisClientClass,
227229
array_map('strval', $options['dsns']),

Diff for: tests/DependencyInjection/Fixtures/config/yaml/env_predis_ssl_context.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ snc_redis:
1010
options:
1111
parameters:
1212
ssl_context: {'verify_peer': false, 'allow_self_signed': true, 'verify_peer_name': false}
13+
commands:
14+
foo: 'Foo\Bar\Baz'

Diff for: tests/DependencyInjection/SncRedisExtensionEnvTest.php

+35
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,41 @@ public function testPredisDefaultParameterWithSSLContextConfigLoad(): void
4040
);
4141
}
4242

43+
public function testPredisDefaultParameterConfig(): void
44+
{
45+
$container = $this->getConfiguredContainer('env_predis_ssl_context');
46+
47+
$clientDefinition = $container->findDefinition('snc_redis.default');
48+
49+
$this->assertSame('Predis\Client', $clientDefinition->getClass());
50+
$this->assertSame(
51+
[
52+
'parameters' => [
53+
'database' => null,
54+
'username' => null,
55+
'password' => null,
56+
'logging' => false,
57+
],
58+
'commands' => ['foo' => 'Foo\Bar\Baz'],
59+
'read_write_timeout' => null,
60+
'iterable_multibulk' => false,
61+
'serialization' => 'default',
62+
'prefix' => null,
63+
'service' => null,
64+
'async_connect' => false,
65+
'timeout' => 5,
66+
'persistent' => false,
67+
'exceptions' => true,
68+
'ssl' => [
69+
'verify_peer' => false,
70+
'allow_self_signed' => true,
71+
'verify_peer_name' => false,
72+
],
73+
],
74+
$container->findDefinition((string) $clientDefinition->getArgument(1))->getArgument(0),
75+
);
76+
}
77+
4378
/**
4479
* @testWith ["env_phpredis_minimal", "Redis"]
4580
* ["env_relay_minimal", "Relay\\Relay"]

0 commit comments

Comments
 (0)