8000 [Cache] Add type to redis scan call to avoid using default "" which r… by mfadul24 · Pull Request #51838 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Cache] Add type to redis scan call to avoid using default "" which r… #51838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Cache] Add type to redis scan call to avoid using default "" which r…
…eturns empty array
  • Loading branch information
mfadul24 committed Oct 10, 2023
commit d97cfdd1843064d68d990803ba65903f1bf810f3
34 changes: 27 additions & 7 deletions src/Symfony/Component/Cache/Tests/Traits/RedisTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@

class RedisTraitTest extends TestCase
{
public static function setUpBeforeClass(): void
{
if (!getenv('REDIS_CLUSTER_HOSTS')) {
throw new SkippedTestSuiteError('REDIS_CLUSTER_HOSTS env var is not defined.');
}
}

/**
* @dataProvider provideCreateConnection
*/
Expand Down Expand Up @@ -65,4 +58,31 @@ public static function provideCreateConnection(): array
],
];
}

public function testClearUsesValidType()
{
if (!class_exists(\Redis::class)) {
throw new SkippedTestSuiteError(sprintf('The "%s" class is required.', \Redis::class));
}
$redisMock = $this->getMockBuilder(\Redis::class)
->disableOriginalConstructor()
->getMock();
$redisMock->method('info')->willReturn(['redis_version' => '3.0.0']);
$redisMock->expects(self::once())
->method('scan')
->with(null, 'some-namespace*', 1000, 'string')
->willReturn([0, []]);
$mock = new class($redisMock) {
use RedisTrait {
doClear as public;
}

public function __construct($redis)
{
$this->redis = $redis;
}
};

$mock->doClear('some-namespace');
}
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Traits/RedisTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ protected function doClear(string $namespace)

$cursor = null;
do {
$keys = $host instanceof \Predis\ClientInterface ? $host->scan($cursor, 'MATCH', $pattern, 'COUNT', 1000) : $host->scan($cursor, $pattern, 1000);
$keys = $host instanceof \Predis\ClientInterface ? $host->scan($cursor, 'MATCH', $pattern, 'COUNT', 1000) : $host->scan($cursor, $pattern, 1000, 'string');
if (isset($keys[1]) && \is_array($keys[1])) {
$cursor = $keys[0];
$keys = $keys[1];
Expand Down
0