mirror of
https://github.com/predis/predis.git
synced 2026-09-01 13:19:39 +00:00
Added support for CF.COUNT command (#1052)
Co-authored-by: Vladyslav Vildanov <vladyslavvildanov@Vladyslav-Vildanov-MacBook-Pro.local>
This commit is contained in:
committed by
GitHub
parent
0bdfcddcc1
commit
eb4c5c349d
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?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.count/
|
||||
*
|
||||
* Returns the number of times an item may be in the filter.
|
||||
* Because this is a probabilistic data structure, this may not necessarily be accurate.
|
||||
*/
|
||||
class CFCOUNT extends RedisCommand
|
||||
{
|
||||
public function getId()
|
||||
{
|
||||
return 'CF.COUNT';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?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;
|
||||
|
||||
class CFCOUNT_Test extends PredisCommandTestCase
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getExpectedCommand(): string
|
||||
{
|
||||
return CFCOUNT::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getExpectedId(): string
|
||||
{
|
||||
return 'CFCOUNT';
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user