diff --git a/src/ClientContextInterface.php b/src/ClientContextInterface.php index 868501f9..16314bef 100644 --- a/src/ClientContextInterface.php +++ b/src/ClientContextInterface.php @@ -45,6 +45,7 @@ use Predis\Command\CommandInterface; * @method $this bfadd(string $key, $item) * @method $this bfexists(string $key, $item) * @method $this bfinfo(string $key, string $modifier = '') + * @method $this bfloadchunk(string $key, int $iterator, $data) * @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) diff --git a/src/ClientInterface.php b/src/ClientInterface.php index 10b56037..20a1e334 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -54,6 +54,7 @@ use Predis\Response\Status; * @method int bfadd(string $key, $item) * @method int bfexists(string $key, $item) * @method array bfinfo(string $key, string $modifier = '') + * @method Status bfloadchunk(string $key, int $iterator, $data) * @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) diff --git a/src/Command/Redis/BloomFilter/BFLOADCHUNK.php b/src/Command/Redis/BloomFilter/BFLOADCHUNK.php new file mode 100644 index 00000000..76a78e99 --- /dev/null +++ b/src/Command/Redis/BloomFilter/BFLOADCHUNK.php @@ -0,0 +1,28 @@ +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 testLoadChunkSuccessfullyRestoresBloomFilter(): void + { + $redis = $this->getClient(); + + $redis->bfadd('key', 'item1'); + + $chunks = []; + $iter = 0; + + while (true) { + [$iter, $data] = $redis->bfscandump('key', $iter); + + if ($iter === 0) { + break; + } + + $chunks[] = [$iter, $data]; + } + + $redis->flushall(); + + foreach ($chunks as $chunk) { + [$iter, $data] = $chunk; + $actualResponse = $redis->bfloadchunk('key', $iter, $data); + + $this->assertEquals('OK', $actualResponse); + } + + $this->assertSame(1, $redis->bfexists('key', 'item1')); + } + + /** + * @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('bfloadchunk_foo', 'bar'); + $redis->bfloadchunk('bfloadchunk_foo', 0, 'data'); + } +}