mirror of
https://github.com/predis/predis.git
synced 2026-08-18 13:13:04 +00:00
Add support for TDIGEST.REVRANK command (#1105)
Co-authored-by: Vladyslav Vildanov <vladyslavvildanov@Vladyslav-Vildanov-MacBook-Pro.local>
This commit is contained in:
committed by
GitHub
parent
23356ceb8e
commit
55e2f74447
@@ -184,6 +184,7 @@ use Predis\Command\CommandInterface;
|
||||
* @method $this tdigestmin(string $key)
|
||||
* @method $this tdigestrank(string $key, ...$value)
|
||||
* @method $this tdigestreset(string $key)
|
||||
* @method $this tdigestrevrank(string $key, float ...$value)
|
||||
* @method $this zadd($key, array $membersAndScoresDictionary)
|
||||
* @method $this zcard($key)
|
||||
* @method $this zcount($key, $min, $max)
|
||||
|
||||
@@ -194,6 +194,7 @@ use Predis\Response\Status;
|
||||
* @method string tdigestmin(string $key)
|
||||
* @method array tdigestrank(string $key, float ...$value)
|
||||
* @method Status tdigestreset(string $key)
|
||||
* @method array tdigestrevrank(string $key, float ...$value)
|
||||
* @method string xadd(string $key, array $dictionary, string $id = '*', array $options = null)
|
||||
* @method int xdel(string $key, string ...$id)
|
||||
* @method int xlen(string $key)
|
||||
|
||||
@@ -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\TDigest;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see https://redis.io/commands/tdigest.revrank/
|
||||
*
|
||||
* Returns, for each input value (floating-point), the estimated reverse rank
|
||||
* of the value (the number of observations in the sketch that are larger than
|
||||
* the value + half the number of observations that are equal to the value).
|
||||
*/
|
||||
class TDIGESTREVRANK extends RedisCommand
|
||||
{
|
||||
public function getId()
|
||||
{
|
||||
return 'TDIGEST.REVRANK';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?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\TDigest;
|
||||
|
||||
use Predis\Command\Redis\PredisCommandTestCase;
|
||||
use Predis\Response\ServerException;
|
||||
|
||||
class TDIGESTREVRANK_Test extends PredisCommandTestCase
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getExpectedCommand(): string
|
||||
{
|
||||
return TDIGESTREVRANK::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getExpectedId(): string
|
||||
{
|
||||
return 'TDIGESTREVRANK';
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testFilterArguments(): void
|
||||
{
|
||||
$actualArguments = ['key', 1, 2, 3];
|
||||
$expectedArguments = ['key', 1, 2, 3];
|
||||
|
||||
$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 >= 2.4.0
|
||||
*/
|
||||
public function testReturnsReversedRanksOfGivenObservationsValue(): void
|
||||
{
|
||||
$redis = $this->getClient();
|
||||
$expectedResponse = [3, 2, 1, 0, -1];
|
||||
|
||||
$redis->tdigestcreate('key');
|
||||
$redis->tdigestcreate('empty_key');
|
||||
|
||||
$redis->tdigestadd('key', 10, 20, 30);
|
||||
|
||||
$actualResponse = $redis->tdigestrevrank('key', 0, 10, 20, 30, 40);
|
||||
|
||||
$this->assertSame($expectedResponse, $actualResponse);
|
||||
$this->assertSame([-2, -2, -2], $redis->tdigestrank('empty_key', 1, 2, 3));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @return void
|
||||
* @requiresRedisBfVersion >= 2.4.0
|
||||
*/
|
||||
public function testThrowsExceptionOnNonExistingTDigestSketch(): void
|
||||
{
|
||||
$redis = $this->getClient();
|
||||
|
||||
$this->expectException(ServerException::class);
|
||||
$this->expectExceptionMessage('ERR T-Digest: key does not exist');
|
||||
|
||||
$redis->tdigestrevrank('key', 1, 2, 3);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user