Extended Bloom Filter by implementing BF.SCANDUMP command (#889)

* 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 <vladyslavvildanov@Vladyslav-Vildanov-MacBook-Pro.local>
Co-authored-by: Till Krüss <tillkruss@users.noreply.github.com>
This commit is contained in:
Vladyslav Vildanov
2023-01-26 14:41:14 +02:00
committed by GitHub
parent 549b4414c4
commit 87ef63e9da
4 changed files with 124 additions and 0 deletions
+1
View File
@@ -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)
+1
View File
@@ -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)
@@ -0,0 +1,29 @@
<?php
/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Predis\Command\Redis\BloomFilter;
use Predis\Command\Command as RedisCommand;
/**
* @see https://redis.io/commands/bf.scandump/
*
* Begins an incremental save of the bloom filter.
* This is useful for large bloom filters which cannot fit into the normal DUMP and RESTORE model.
*/
class BFSCANDUMP extends RedisCommand
{
public function getId()
{
return 'BF.SCANDUMP';
}
}
@@ -0,0 +1,93 @@
<?php
/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Predis\Command\Redis\BloomFilter;
use Predis\Command\Redis\PredisCommandTestCase;
use Predis\Response\ServerException;
/**
* @group commands
* @group realm-bloom
*/
class BFSCANDUMP_Test extends PredisCommandTestCase
{
/**
* {@inheritDoc}
*/
protected function getExpectedCommand(): string
{
return BFSCANDUMP::class;
}
/**
* {@inheritDoc}
*/
protected function getExpectedId(): string
{
return 'BFSCANDUMP';
}
/**
* @group disconnected
*/
public function testFilterArguments(): void
{
$actualArguments = ['key', 1];
$expectedArguments = ['key', 1];
$command = $this->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);
}
}