From 87ef63e9da473d4f4f674455de3d6a8e61eeea02 Mon Sep 17 00:00:00 2001 From: Vladyslav Vildanov <117659936+vladvildanov@users.noreply.github.com> Date: Thu, 26 Jan 2023 14:41:14 +0200 Subject: [PATCH] Extended Bloom Filter by implementing BF.SCANDUMP command (#889) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added CommandResolver, moved resolve command logic there, added ClientConfiguration object * Fixed test, added dependecies * Added resolved command to commands array * Used aggregation approach for modules * Added decorator to check Redis JSON module version * Added support for JSON.SET and JSON.GET commands * Added separate workflow for redis-stack tests * Changed docker imange name to correct one * Fixed indentation * Added test coverage for JSON.GET command * Changed module version resolving using annotations mapping * Re-written CommandResolver test * Update ClientInterface.php * Changes to CI, readme, removed unused modules from configuration * Fixed build badge URL * Refactored annotation check to be generic for each module * Added support for BF.ADD and BF.EXISTS commands * Fixed bug with incorrect tests skip * Added support for BF.SCANDUMP command Co-authored-by: Vladyslav Vildanov Co-authored-by: Till Krüss --- src/ClientContextInterface.php | 1 + src/ClientInterface.php | 1 + src/Command/Redis/BloomFilter/BFSCANDUMP.php | 29 ++++++ .../Redis/BloomFilter/BFSCANDUMP_Test.php | 93 +++++++++++++++++++ 4 files changed, 124 insertions(+) create mode 100644 src/Command/Redis/BloomFilter/BFSCANDUMP.php create mode 100644 tests/Predis/Command/Redis/BloomFilter/BFSCANDUMP_Test.php diff --git a/src/ClientContextInterface.php b/src/ClientContextInterface.php index 602a9087..868501f9 100644 --- a/src/ClientContextInterface.php +++ b/src/ClientContextInterface.php @@ -48,6 +48,7 @@ use Predis\Command\CommandInterface; * @method $this bfmadd(string $key, ...$item) * @method $this bfmexists(string $key, ...$item) * @method $this bfreserve(string $key, float $errorRate, int $capacity, int $expansion = -1, bool $nonScaling = false) + * @method $this bfscandump(string $key, int $iterator) * @method $this bitcount($key, $start = null, $end = null) * @method $this bitop($operation, $destkey, $key) * @method $this bitfield($key, $subcommand, ...$subcommandArg) diff --git a/src/ClientInterface.php b/src/ClientInterface.php index af00d98d..10b56037 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -57,6 +57,7 @@ use Predis\Response\Status; * @method array bfmadd(string $key, ...$item) * @method array bfmexists(string $key, ...$item) * @method Status bfreserve(string $key, float $errorRate, int $capacity, int $expansion = -1, bool $nonScaling = false) + * @method array bfscandump(string $key, int $iterator) * @method int bitcount(string $key, $start = null, $end = null) * @method int bitop($operation, $destkey, $key) * @method array|null bitfield(string $key, $subcommand, ...$subcommandArg) diff --git a/src/Command/Redis/BloomFilter/BFSCANDUMP.php b/src/Command/Redis/BloomFilter/BFSCANDUMP.php new file mode 100644 index 00000000..f8576d2d --- /dev/null +++ b/src/Command/Redis/BloomFilter/BFSCANDUMP.php @@ -0,0 +1,29 @@ +getCommand(); + $command->setArguments($actualArguments); + + $this->assertSameValues($expectedArguments, $command->getArguments()); + } + + /** + * @group disconnected + */ + public function testParseResponse(): void + { + $this->assertSame(1, $this->getCommand()->parseResponse(1)); + } + + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 1.0.0 + */ + public function testScanDumpReturnsCorrectDataChunk(): void + { + $expectedIterator = 1; + $redis = $this->getClient(); + + $redis->bfadd('key', 'item1'); + [$iterator, $dataChunk] = $redis->bfscandump('key', 0); + + $this->assertSame($expectedIterator, $iterator); + $this->assertNotEmpty($dataChunk); + } + + /** + * @group connected + * @requiresRedisBfVersion >= 1.0.0 + */ + public function testThrowsExceptionOnWrongType(): void + { + $this->expectException(ServerException::class); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + + $redis = $this->getClient(); + + $redis->set('bfscandump_foo', 'bar'); + $redis->bfscandump('bfscandump_foo', 0); + } +}