Extend Bloom filters by imlplementing BFMADD and BFMEXISTS commands (#887)

* 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.MADD and BF.MEXISTS commands

* Removed old file

* Revert changes

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 11:19:31 +02:00
committed by GitHub
parent 1170d09ac5
commit f82bee9a81
6 changed files with 224 additions and 0 deletions
+2
View File
@@ -45,6 +45,8 @@ 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 bfmadd(string $key, ...$item)
* @method $this bfmexists(string $key, ...$item)
* @method $this bitcount($key, $start = null, $end = null)
* @method $this bitop($operation, $destkey, $key)
* @method $this bitfield($key, $subcommand, ...$subcommandArg)
+2
View File
@@ -54,6 +54,8 @@ use Predis\Response\Status;
* @method int bfadd(string $key, $item)
* @method int bfexists(string $key, $item)
* @method array bfinfo(string $key, string $modifier = '')
* @method array bfmadd(string $key, ...$item)
* @method array bfmexists(string $key, ...$item)
* @method int bitcount(string $key, $start = null, $end = null)
* @method int bitop($operation, $destkey, $key)
* @method array|null bitfield(string $key, $subcommand, ...$subcommandArg)
+29
View File
@@ -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.madd/
*
* Adds one or more items to the Bloom Filter and creates the filter if it does not exist yet.
* This command operates identically to BF.ADD except that it allows multiple inputs and returns multiple values.
*/
class BFMADD extends RedisCommand
{
public function getId()
{
return 'BF.MADD';
}
}
@@ -0,0 +1,28 @@
<?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.mexists/
*
* Determines if one or more items may exist in the filter or not.
*/
class BFMEXISTS extends RedisCommand
{
public function getId()
{
return 'BF.MEXISTS';
}
}
@@ -0,0 +1,90 @@
<?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 BFMADD_Test extends PredisCommandTestCase
{
/**
* {@inheritDoc}
*/
protected function getExpectedCommand(): string
{
return BFMADD::class;
}
/**
* {@inheritDoc}
*/
protected function getExpectedId(): string
{
return 'BFMADD';
}
/**
* @group disconnected
*/
public function testFilterArguments(): void
{
$actualArguments = ['key', 'item1', 'item2'];
$expectedArguments = ['key', 'item1', 'item2'];
$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
*/
public function testAddGivenItemsIntoBloomFilter(): void
{
$redis = $this->getClient();
$actualResponse = $redis->bfmadd('key', 'item1', 'item2');
$this->assertSame([1, 1], $actualResponse);
$this->assertSame([1, 1], $redis->bfmexists('key', 'item1', 'item2'));
}
/**
* @group connected
* @requiresRedisBfVersion >= 1.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('bfmadd_foo', 'bar');
$redis->bfmadd('bfmadd_foo', 'foo');
}
}
@@ -0,0 +1,73 @@
<?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;
/**
* @group commands
* @group realm-bloom
*/
class BFMEXISTS_Test extends PredisCommandTestCase
{
/**
* {@inheritDoc}
*/
protected function getExpectedCommand(): string
{
return BFMEXISTS::class;
}
/**
* {@inheritDoc}
*/
protected function getExpectedId(): string
{
return 'BFMEXISTS';
}
/**
* @group disconnected
*/
public function testFilterArguments(): void
{
$actualArguments = ['key', 'item1', 'item2'];
$expectedArguments = ['key', 'item1', 'item2'];
$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
*/
public function testExistsReturnsExistingItemsWithinBloomFilter(): void
{
$redis = $this->getClient();
$redis->bfmadd('key', 'item1', 'item2');
$this->assertSame([1, 1], $redis->bfmexists('key', 'item1', 'item2'));
}
}