diff --git a/src/ClientContextInterface.php b/src/ClientContextInterface.php index 53b4edad..c8678ad7 100644 --- a/src/ClientContextInterface.php +++ b/src/ClientContextInterface.php @@ -62,6 +62,7 @@ use Predis\Command\CommandInterface; * @method $this cfadd(string $key, $item) * @method $this cfaddnx(string $key, $item) * @method $this cfcount(string $key, $item) + * @method $this cfdel(string $key, $item) * @method $this cfexists(string $key, $item) * @method $this cfmexists(string $key, ...$item) * @method $this cfinfo(string $key) diff --git a/src/ClientInterface.php b/src/ClientInterface.php index bd619c9b..c96f5f50 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -71,6 +71,7 @@ use Predis\Response\Status; * @method int cfadd(string $key, $item) * @method int cfaddnx(string $key, $item) * @method int cfcount(string $key, $item) + * @method int cfdel(string $key, $item) * @method int cfexists(string $key, $item) * @method int cfmexists(string $key, ...$item) * @method array cfinfo(string $key) diff --git a/src/Command/Redis/CuckooFilter/CFDEL.php b/src/Command/Redis/CuckooFilter/CFDEL.php new file mode 100644 index 00000000..adbd29ea --- /dev/null +++ b/src/Command/Redis/CuckooFilter/CFDEL.php @@ -0,0 +1,30 @@ +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 + * @requiresRedisVersion >= 7.0.0 + */ + public function testDeletesItemFromGivenCuckooFilter(): void + { + $redis = $this->getClient(); + + $redis->cfadd('key', 'item'); + $singleItemResponse = $redis->cfdel('key', 'item'); + + $this->assertSame(1, $singleItemResponse); + $this->assertSame(0, $redis->cfexists('key', 'item')); + + $redis->cfadd('key', 'item'); + $redis->cfadd('key', 'item'); + + $multipleItemsResponse = $redis->cfdel('key', 'item'); + $this->assertSame(1, $multipleItemsResponse); + $this->assertSame(1, $redis->cfexists('key', 'item')); + + $nonExistingItemResponse = $redis->cfdel('key', 'non_existing_item'); + $this->assertSame(0, $nonExistingItemResponse); + } + + /** + * @group connected + * @return void + * @requiresRedisVersion >= 7.0.0 + */ + public function testDeleteThrowsExceptionOnNonExistingFilterKey(): void + { + $redis = $this->getClient(); + + $this->expectException(ServerException::class); + $this->expectExceptionMessage('Not found'); + + $redis->cfdel('non_existing_key', 'item'); + } +}