Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d97cfdd

Browse filesBrowse files
committed
[Cache] Add type to redis scan call to avoid using default "" which returns empty array
1 parent 28ba7d9 commit d97cfdd
Copy full SHA for d97cfdd

File tree

Expand file treeCollapse file tree

2 files changed

+28
-8
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+28
-8
lines changed

‎src/Symfony/Component/Cache/Tests/Traits/RedisTraitTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Tests/Traits/RedisTraitTest.php
+27-7Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@
1717

1818
class RedisTraitTest extends TestCase
1919
{
20-
public static function setUpBeforeClass(): void
21-
{
22-
if (!getenv('REDIS_CLUSTER_HOSTS')) {
23-
throw new SkippedTestSuiteError('REDIS_CLUSTER_HOSTS env var is not defined.');
24-
}
25-
}
26-
2720
/**
2821
* @dataProvider provideCreateConnection
2922
*/
@@ -65,4 +58,31 @@ public static function provideCreateConnection(): array
6558
],
6659
];
6760
}
61+
62+
public function testClearUsesValidType()
63+
{
64+
if (!class_exists(\Redis::class)) {
65+
throw new SkippedTestSuiteError(sprintf('The "%s" class is required.', \Redis::class));
66+
}
67+
$redisMock = $this->getMockBuilder(\Redis::class)
68+
->disableOriginalConstructor()
69+
->getMock();
70+
$redisMock->method('info')->willReturn(['redis_version' => '3.0.0']);
71+
$redisMock->expects(self::once())
72+
->method('scan')
73+
->with(null, 'some-namespace*', 1000, 'string')
74+
->willReturn([0, []]);
75+
$mock = new class($redisMock) {
76+
use RedisTrait {
77+
doClear as public;
78+
}
79+
80+
public function __construct($redis)
81+
{
82+
$this->redis = $redis;
83+
}
84+
};
85+
86+
$mock->doClear('some-namespace');
87+
}
6888
}

‎src/Symfony/Component/Cache/Traits/RedisTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Traits/RedisTrait.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ protected function doClear(string $namespace)
476476

477477
$cursor = null;
478478
do {
479-
$keys = $host instanceof \Predis\ClientInterface ? $host->scan($cursor, 'MATCH', $pattern, 'COUNT', 1000) : $host->scan($cursor, $pattern, 1000);
479+
$keys = $host instanceof \Predis\ClientInterface ? $host->scan($cursor, 'MATCH', $pattern, 'COUNT', 1000) : $host->scan($cursor, $pattern, 1000, 'string');
480480
if (isset($keys[1]) && \is_array($keys[1])) {
481481
$cursor = $keys[0];
482482
$keys = $keys[1];

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.