Skip to content
Merged
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
4 changes: 4 additions & 0 deletions system/Cache/Handlers/PredisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ public function deleteMatching(string $pattern)
$matchedKeys[] = $key;
}

if ($matchedKeys === []) {
return 0;
}

return $this->redis->del($matchedKeys);
}

Expand Down
2 changes: 1 addition & 1 deletion system/Cache/Handlers/RedisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public function deleteMatching(string $pattern)
}
} while ($iterator > 0);

return $this->redis->del($matchedKeys);
return (int) $this->redis->del($matchedKeys);
}

/**
Expand Down
5 changes: 5 additions & 0 deletions tests/system/Cache/Handlers/PredisHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ public function testDeleteMatchingSuffix(): void
$this->assertSame('90', $this->handler->getCacheInfo()['Keyspace']['db0']['keys']);
}

public function testDeleteMatchingNothing(): void
{
$this->assertSame(0, $this->handler->deleteMatching('user_1_info*'));
}

public function testClean(): void
{
$this->handler->save(self::$key1, 1);
Expand Down
5 changes: 5 additions & 0 deletions tests/system/Cache/Handlers/RedisHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ public static function provideDeleteMatching(): iterable
yield 'cache-prefix' => ['key_1*', 13, 'foo_'];
}

public function testDeleteMatchingNothing(): void
{
$this->assertSame(0, $this->handler->deleteMatching('user_1_info*'));
}

public function testIncrementAndDecrement(): void
{
$this->handler->save('counter', 100);
Expand Down
2 changes: 2 additions & 0 deletions user_guide_src/source/changelogs/v4.6.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Deprecations
Bugs Fixed
**********

- **Cache:** Fixed a bug in ``PredisHandler::deleteMatching()`` causing Redis error when no keys match the pattern.
- **Cache:** Fixed a bug in ``RedisHandler::deleteMatching()`` returning ``false`` instead of ``int`` when no keys match the pattern.
- **Database:** Fixed a bug in ``Database::connect()`` which was causing to store non-shared connection instances in shared cache.
- **Database:** Fixed a bug in ``Connection::getFieldData()`` for ``SQLSRV`` and ``OCI8`` where extra characters were returned in column default values (specific to those handlers), instead of following the convention used by other drivers.
- **Database:** Fixed a bug in ``BaseBuilder::compileOrderBy()`` where the method could overwrite ``QBOrderBy`` with a string instead of keeping it as an array, causing type errors and preventing additional ``ORDER BY`` clauses from being appended.
Expand Down
Loading