Skip to content

Commit bda25c6

Browse files
committed
Fix bunch of things and rebase
1 parent f2aeb48 commit bda25c6

File tree

9 files changed

+21
-57
lines changed

9 files changed

+21
-57
lines changed

docs/README.md

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -295,21 +295,6 @@ framework:
295295
provider: snc_redis.cache
296296
```
297297

298-
### PhpRedis Scan Option ###
299-
300-
To enable the `SCAN_PREFIX` feature for PhpRedis clients, add the `scan` option:
301-
302-
```yaml
303-
snc_redis:
304-
clients:
305-
default:
306-
type: phpredis
307-
alias: default
308-
dsn: redis://localhost
309-
options:
310-
scan: prefix
311-
```
312-
313298
### Complete configuration example ###
314299

315300
``` yaml
@@ -338,7 +323,7 @@ snc_redis:
338323
connection_timeout: 10
339324
connection_persistent: true
340325
read_write_timeout: 30
341-
scan: prefix
326+
scan: !php/const REDIS::SCAN_PREFIX # OPT_SCAN option, phpredis only
342327
iterable_multibulk: false
343328
throw_errors: true
344329
cluster: predis

src/DependencyInjection/Configuration/Configuration.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ private function addClientsSection(ArrayNodeDefinition $rootNode): void
134134
->end()
135135
->end()
136136
->scalarNode('connection_timeout')->cannotBeEmpty()->defaultValue(5)->end()
137-
->scalarNode('scan')->defaultNull()->end()
137+
->integerNode('scan')
138+
->defaultValue(0) // Redis::SCAN_NORETRY
139+
->end()
138140
->scalarNode('read_write_timeout')->defaultNull()->end()
139141
->booleanNode('iterable_multibulk')->defaultFalse()->end()
140142
->booleanNode('throw_errors')->defaultTrue()->end()

src/DependencyInjection/SncRedisExtension.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use InvalidArgumentException;
1717
use LogicException;
1818
use Predis\Client;
19-
use Redis;
2019
use RedisSentinel;
2120
use Relay\Sentinel;
2221
use Snc\RedisBundle\DependencyInjection\Configuration\Configuration;
@@ -161,10 +160,6 @@ private function loadPredisClient(array $client, ContainerBuilder $container): v
161160
// fix ssl configuration key name
162161
$client['options']['ssl'] = $client['options']['parameters']['ssl_context'] ?? [];
163162

164-
if (isset($client['options']['scan']) && $client['options']['scan'] === 'prefix') {
165-
$client['options']['scan'] = Redis::SCAN_PREFIX;
166-
}
167-
168163
unset($client['options']['connection_async']);
169164
unset($client['options']['connection_timeout']);
170165
unset($client['options']['connection_persistent']);

src/Factory/PhpredisClientFactory.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,8 @@ private function createClient(RedisDsn $dsn, string $class, string $alias, array
301301
$client->setOption($class::OPT_PREFIX, $options['prefix']);
302302
}
303303

304-
// Support for scan option since https://github.com/phpredis/phpredis/issues/548
305-
if (isset($options['scan']) && $options['scan'] === 'prefix') {
306-
$client->setOption($class::OPT_SCAN, $class::SCAN_PREFIX);
304+
if (isset($options['scan'])) {
305+
$client->setOption($class::OPT_SCAN, $options['scan']);
307306
}
308307

309308
if (isset($options['read_write_timeout'])) {

src/Factory/PredisParametersFactory.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use InvalidArgumentException;
88
use Predis\Connection\ParametersInterface;
9-
use Redis;
109
use Snc\RedisBundle\DependencyInjection\Configuration\RedisDsn;
1110

1211
use function array_filter;
@@ -28,13 +27,8 @@ public static function create(array $options, string $class, string $dsn): Param
2827
}
2928

3029
$defaultOptions = ['timeout' => null]; // Allow to be consistent with old version of Predis where default timeout was 5
31-
32-
if (isset($options['scan']) && $options['scan'] === 'prefix') {
33-
$dsnOptions[Redis::OPT_SCAN] = Redis::SCAN_PREFIX;
34-
}
35-
36-
$dsnOptions = static::parseDsn(new RedisDsn($dsn));
37-
$dsnOptions = array_merge($defaultOptions, $options, $dsnOptions);
30+
$dsnOptions = static::parseDsn(new RedisDsn($dsn));
31+
$dsnOptions = array_merge($defaultOptions, $options, $dsnOptions);
3832

3933
if (!empty($dsnOptions['persistent']) && !empty($dsnOptions['database'])) {
4034
$dsnOptions['persistent'] = (int) $dsnOptions['database'];

tests/DependencyInjection/Fixtures/config/yaml/env_phpredis_full.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ snc_redis:
1212
connection_timeout: 10
1313
connection_persistent: true
1414
prefix: totoprofix
15+
scan: !php/const Redis::SCAN_PREFIX
1516
serialization: php
1617
parameters:
1718
ssl_context: {'verify_peer': false, 'allow_self_signed': true, 'verify_peer_name': false}

tests/DependencyInjection/SncRedisExtensionEnvTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function testPredisDefaultParameterConfig(): void
5959
'logging' => false,
6060
],
6161
'commands' => ['foo' => 'Foo\Bar\Baz'],
62-
'scan' => null,
62+
'scan' => 0,
6363
'read_write_timeout' => null,
6464
'iterable_multibulk' => false,
6565
'serialization' => 'default',
@@ -99,7 +99,7 @@ public function testPhpredisDefaultParameterConfig(string $config, string $class
9999
'connection_async' => false,
100100
'connection_persistent' => false,
101101
'connection_timeout' => 5,
102-
'scan' => null,
102+
'scan' => 0,
103103
'read_write_timeout' => null,
104104
'iterable_multibulk' => false,
105105
'throw_errors' => true,
@@ -127,6 +127,7 @@ public function testPhpredisFullConfig(): void
127127
'connection_timeout' => 10,
128128
'connection_persistent' => true,
129129
'prefix' => 'totoprofix',
130+
'scan' => 2,
130131
'serialization' => 'php',
131132
'parameters' => [
132133
'ssl_context' => [
@@ -142,7 +143,6 @@ public function testPhpredisFullConfig(): void
142143
'logging' => false,
143144
],
144145
'connection_async' => false,
145-
'scan' => null,
146146
'read_write_timeout' => null,
147147
'iterable_multibulk' => false,
148148
'throw_errors' => true,
@@ -186,7 +186,7 @@ public function testPhpredisWithAclConfig(): void
186186
'serialization' => 'php',
187187
'service' => null,
188188
'throw_errors' => true,
189-
'scan' => null,
189+
'scan' => 0,
190190
],
191191
$clientDefinition->getArgument(2),
192192
);
@@ -225,7 +225,7 @@ public function testPhpRedisClusterOption(): void
225225
'connection_async' => false,
226226
'connection_persistent' => false,
227227
'connection_timeout' => 5,
228-
'scan' => null,
228+
'scan' => 0,
229229
'read_write_timeout' => null,
230230
'iterable_multibulk' => false,
231231
'throw_errors' => true,
@@ -255,7 +255,7 @@ public function testPhpRedisSentinelOption(): void
255255
'connection_async' => false,
256256
'connection_persistent' => false,
257257
'connection_timeout' => 5,
258-
'scan' => null,
258+
'scan' => 0,
259259
'read_write_timeout' => null,
260260
'iterable_multibulk' => false,
261261
'throw_errors' => true,
@@ -286,7 +286,7 @@ public function testPhpRedisClusterOptionMultipleDsn(): void
286286
'connection_timeout' => 1.5,
287287
'connection_persistent' => true,
288288
'connection_async' => false,
289-
'scan' => null,
289+
'scan' => 0,
290290
'iterable_multibulk' => false,
291291
'throw_errors' => true,
292292
'serialization' => 'default',

tests/Factory/PhpredisClientFactoryTest.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ public function testCreateFullConfig(): void
191191
'connection_timeout' => 10,
192192
'connection_persistent' => 'x',
193193
'prefix' => 'toto',
194+
'scan' => Redis::SCAN_PREFIX,
194195
'serialization' => 'php',
195196
'read_write_timeout' => 4,
196197
'parameters' => [
@@ -210,6 +211,7 @@ public function testCreateFullConfig(): void
210211
$this->assertSame('sncredis', $client->getAuth());
211212
$this->assertNotNull($client->getPersistentID());
212213
$this->assertNotFalse($client->getPersistentID());
214+
$this->assertEquals(Redis::SCAN_PREFIX, $client->getOption(Redis::OPT_SCAN));
213215
}
214216

215217
public function testDsnConfig(): void
@@ -468,19 +470,4 @@ public function testCreateWithConnectionPersistentFalse(): void
468470
$this->assertInstanceOf(Redis::class, $client);
469471
$this->assertNull($client->getPersistentID());
470472
}
471-
472-
public function testScanOption(): void
473-
{
474-
$factory = new PhpredisClientFactory(new RedisCallInterceptor($this->redisLogger));
475-
$options = [
476-
'connection_timeout' => 0.0,
477-
'connection_persistent' => false,
478-
'scan' => 'prefix',
479-
];
480-
481-
$client = $factory->create(Redis::class, ['redis://localhost:6379'], $options, 'default', false);
482-
483-
$this->assertInstanceOf(Redis::class, $client);
484-
$this->assertEquals(Redis::SCAN_PREFIX, $client->getOption(Redis::OPT_SCAN));
485-
}
486473
}

tests/Factory/PredisParametersFactoryTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ public static function createDp(): array
128128
'everything in DSN' => [
129129
'rediss://pw@localhost:6380/0?prefix=foo&alias=connection_alias',
130130
[],
131-
$allOptions = [
131+
$allOptions =
132+
[
132133
'scheme' => 'tls',
133134
'host' => 'localhost',
134135
'port' => 6380,
@@ -138,7 +139,7 @@ public static function createDp(): array
138139
'alias' => 'connection_alias',
139140
],
140141
],
141-
'everything in options' => ['rediss://localhost:6380', $allOptions, $allOptions]
142+
'everything in options' => ['rediss://localhost:6380', $allOptions, $allOptions],
142143
];
143144
}
144145

0 commit comments

Comments
 (0)