Added support for Cuckoo Filter, added CF.ADD and CF.EXISTS commands (#907)

* 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

* Changed module name according to original naming

* Added support for CF.ADD and CF.EXISTS commands

* Removed old files

* Revert old 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-25 18:48:14 +02:00
committed by GitHub
parent 7b7e93a53f
commit ca498b67a1
7 changed files with 218 additions and 0 deletions
+1
View File
@@ -21,6 +21,7 @@ class ClientConfiguration
'modules' => [
['name' => 'Json', 'commandPrefix' => 'JSON'],
['name' => 'BloomFilter', 'commandPrefix' => 'BF'],
['name' => 'CuckooFilter', 'commandPrefix' => 'CF'],
],
];
+2
View File
@@ -52,6 +52,8 @@ use Predis\Command\CommandInterface;
* @method $this bzpopmax(array $keys, int $timeout)
* @method $this bzpopmin(array $keys, int $timeout)
* @method $this bzmpop(int $timeout, array $keys, string $modifier = 'min', int $count = 1)
* @method $this cfadd(string $key, $item)
* @method $this cfexists(string $key, $item)
* @method $this decr($key)
* @method $this decrby($key, $decrement)
* @method $this failover(?To $to = null, bool $abort = false, int $timeout = -1)
+2
View File
@@ -61,6 +61,8 @@ use Predis\Response\Status;
* @method array bzpopmax(array $keys, int $timeout)
* @method array bzpopmin(array $keys, int $timeout)
* @method array bzmpop(int $timeout, array $keys, string $modifier = 'min', int $count = 1)
* @method int cfadd(string $key, $item)
* @method int cfexists(string $key, $item)
* @method int decr(string $key)
* @method int decrby(string $key, int $decrement)
* @method Status failover(?To $to = null, bool $abort = false, int $timeout = -1)
+28
View File
@@ -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\CuckooFilter;
use Predis\Command\Command as RedisCommand;
/**
* @see https://redis.io/commands/cf.add/
*
* Adds an item to the cuckoo filter, creating the filter if it does not exist.
*/
class CFADD extends RedisCommand
{
public function getId()
{
return 'CF.ADD';
}
}
@@ -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\CuckooFilter;
use Predis\Command\Command as RedisCommand;
/**
* @see https://redis.io/commands/cf.exists/
*
* Check if an item exists in a Cuckoo Filter key.
*/
class CFEXISTS extends RedisCommand
{
public function getId()
{
return 'CF.EXISTS';
}
}
@@ -0,0 +1,86 @@
<?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\CuckooFilter;
use Predis\Command\Redis\PredisCommandTestCase;
use Predis\Response\ServerException;
class CFADD_Test extends PredisCommandTestCase
{
/**
* {@inheritDoc}
*/
protected function getExpectedCommand(): string
{
return CFADD::class;
}
/**
* {@inheritDoc}
*/
protected function getExpectedId(): string
{
return 'CFADD';
}
/**
* @group disconnected
*/
public function testFilterArguments(): void
{
$actualArguments = ['key', 'item'];
$expectedArguments = ['key', 'item'];
$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 testAddItemToCuckooFilter(): void
{
$redis = $this->getClient();
$actualResponse = $redis->cfadd('key', 'item');
$this->assertSame(1, $actualResponse);
$this->assertSame(1, $redis->cfexists('key', 'item'));
}
/**
* @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('cfadd_foo', 'bar');
$redis->cfadd('cfadd_foo', 'foo');
}
}
@@ -0,0 +1,71 @@
<?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\CuckooFilter;
use Predis\Command\Redis\PredisCommandTestCase;
class CFEXISTS_Test extends PredisCommandTestCase
{
/**
* {@inheritDoc}
*/
protected function getExpectedCommand(): string
{
return CFEXISTS::class;
}
/**
* {@inheritDoc}
*/
protected function getExpectedId(): string
{
return 'CFEXISTS';
}
/**
* @group disconnected
*/
public function testFilterArguments(): void
{
$actualArguments = ['key', 'item'];
$expectedArguments = ['key', 'item'];
$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 testExistsReturnsExistingItemWithinCuckooFilter(): void
{
$redis = $this->getClient();
$redis->cfadd('key', 'item');
$this->assertSame(1, $redis->cfexists('key', 'item'));
$this->assertSame(0, $redis->cfexists('non-existing key', 'item'));
}
}