Added support for CF.DEL command (#1080)

Co-authored-by: Vladyslav Vildanov <vladyslavvildanov@Vladyslav-Vildanov-MacBook-Pro.local>
This commit is contained in:
Vladyslav Vildanov
2023-02-01 09:14:50 +02:00
committed by GitHub
parent 92d4306dc4
commit 4284409c7b
4 changed files with 130 additions and 0 deletions
+1
View File
@@ -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)
+1
View File
@@ -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)
+30
View File
@@ -0,0 +1,30 @@
<?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.del/
*
* Deletes an item once from the filter.
* If the item exists only once, it will be removed from the filter.
* If the item was added multiple times, it will still be present.
*/
class CFDEL extends RedisCommand
{
public function getId()
{
return 'CF.DEL';
}
}
@@ -0,0 +1,98 @@
<?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 CFDEL_Test extends PredisCommandTestCase
{
/**
* {@inheritDoc}
*/
protected function getExpectedCommand(): string
{
return CFDEL::class;
}
/**
* {@inheritDoc}
*/
protected function getExpectedId(): string
{
return 'CFDEL';
}
/**
* @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
* @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');
}
}