diff --git a/src/ClientConfiguration.php b/src/ClientConfiguration.php index 22dbf868..ef4dcb36 100644 --- a/src/ClientConfiguration.php +++ b/src/ClientConfiguration.php @@ -21,6 +21,7 @@ class ClientConfiguration 'modules' => [ ['name' => 'Json', 'commandPrefix' => 'JSON'], ['name' => 'BloomFilter', 'commandPrefix' => 'BF'], + ['name' => 'CuckooFilter', 'commandPrefix' => 'CF'], ], ]; diff --git a/src/ClientContextInterface.php b/src/ClientContextInterface.php index dd9bff9e..188814cb 100644 --- a/src/ClientContextInterface.php +++ b/src/ClientContextInterface.php @@ -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) diff --git a/src/ClientInterface.php b/src/ClientInterface.php index 000a027a..53e5425c 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -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) diff --git a/src/Command/Redis/CuckooFilter/CFADD.php b/src/Command/Redis/CuckooFilter/CFADD.php new file mode 100644 index 00000000..92d05889 --- /dev/null +++ b/src/Command/Redis/CuckooFilter/CFADD.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 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'); + } +} diff --git a/tests/Predis/Command/Redis/CuckooFilter/CFEXISTS_Test.php b/tests/Predis/Command/Redis/CuckooFilter/CFEXISTS_Test.php new file mode 100644 index 00000000..492c20d9 --- /dev/null +++ b/tests/Predis/Command/Redis/CuckooFilter/CFEXISTS_Test.php @@ -0,0 +1,71 @@ +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')); + } +}