diff --git a/src/ClientContextInterface.php b/src/ClientContextInterface.php index f5e26c6c..0b09c368 100644 --- a/src/ClientContextInterface.php +++ b/src/ClientContextInterface.php @@ -60,6 +60,7 @@ use Predis\Command\CommandInterface; * @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 cfaddnx(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 0d442f90..b8a19056 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -69,6 +69,7 @@ use Predis\Response\Status; * @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 cfaddnx(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/CFADDNX.php b/src/Command/Redis/CuckooFilter/CFADDNX.php new file mode 100644 index 00000000..ff972fd3 --- /dev/null +++ b/src/Command/Redis/CuckooFilter/CFADDNX.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 testAddItemToCuckooFilterWhenExists(): void + { + $redis = $this->getClient(); + + $actualResponse = $redis->cfaddnx('key', 'item'); + $this->assertSame(1, $actualResponse); + $this->assertSame(1, $redis->cfexists('key', 'item')); + + $actualResponse = $redis->cfaddnx('key', 'item'); + $this->assertSame(0, $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('cfaddnx_foo', 'bar'); + $redis->cfaddnx('cfaddnx_foo', 'foo'); + } +}