diff --git a/src/ClientContextInterface.php b/src/ClientContextInterface.php index 0b09c368..e29f8bbb 100644 --- a/src/ClientContextInterface.php +++ b/src/ClientContextInterface.php @@ -61,6 +61,7 @@ use Predis\Command\CommandInterface; * @method $this bzmpop(int $timeout, array $keys, string $modifier = 'min', int $count = 1) * @method $this cfadd(string $key, $item) * @method $this cfaddnx(string $key, $item) + * @method $this cfcount(string $key, $item) * @method $this cfexists(string $key, $item) * @method $this decr($key) * @method $this decrby($key, $decrement) diff --git a/src/ClientInterface.php b/src/ClientInterface.php index b8a19056..f78e56fc 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -70,6 +70,7 @@ use Predis\Response\Status; * @method array bzmpop(int $timeout, array $keys, string $modifier = 'min', int $count = 1) * @method int cfadd(string $key, $item) * @method int cfaddnx(string $key, $item) + * @method int cfcount(string $key, $item) * @method int cfexists(string $key, $item) * @method int decr(string $key) * @method int decrby(string $key, int $decrement) diff --git a/src/Command/Redis/CuckooFilter/CFCOUNT.php b/src/Command/Redis/CuckooFilter/CFCOUNT.php new file mode 100644 index 00000000..7610c2c0 --- /dev/null +++ b/src/Command/Redis/CuckooFilter/CFCOUNT.php @@ -0,0 +1,29 @@ +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 testReturnsCountOfItemsWithinCuckooFilter(): void + { + $redis = $this->getClient(); + + $redis->cfadd('key', 'item'); + + $singleItemResponse = $redis->cfcount('key', 'item'); + $this->assertSame(1, $singleItemResponse); + + $redis->cfadd('key', 'item'); + $redis->cfadd('key', 'item'); + + $multipleItemsResponse = $redis->cfcount('key', 'item'); + $this->assertSame(3, $multipleItemsResponse); + + $nonExistingItemResponse = $redis->cfcount('non_existing_key', 'item'); + $this->assertSame(0, $nonExistingItemResponse); + } +}