Added support for TDIGEST.BYRANK command (#1096)

Co-authored-by: Vladyslav Vildanov <vladyslavvildanov@Vladyslav-Vildanov-MacBook-Pro.local>
This commit is contained in:
Vladyslav Vildanov
2023-02-06 10:09:18 +02:00
committed by GitHub
parent cf539f9ea7
commit 1313a1b4c2
5 changed files with 115 additions and 0 deletions
+1
View File
@@ -174,6 +174,7 @@ use Predis\Command\CommandInterface;
* @method $this sunion(array|string $keys)
* @method $this sunionstore($destination, array|string $keys)
* @method $this tdigestadd(string $key, float ...$value)
* @method $this tdigestbyrank(string $key, int ...$rank)
* @method $this tdigestcreate(string $key, int $compression = 0)
* @method $this tdigestinfo(string $key)
* @method $this zadd($key, array $membersAndScoresDictionary)
+1
View File
@@ -184,6 +184,7 @@ use Predis\Response\Status;
* @method int sunionstore(string $destination, array|string $keys)
* @method int touch(string[]|string $keyOrKeys, string ...$keys = null)
* @method Status tdigestadd(string $key, float ...$value)
* @method array tdigestbyrank(string $key, int ...$rank)
* @method Status tdigestcreate(string $key, int $compression = 0)
* @method array tdigestinfo(string $key)
* @method string xadd(string $key, array $dictionary, string $id = '*', array $options = null)
@@ -0,0 +1,28 @@
<?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.byrank/
*
* Returns, for each input rank, an estimation of the value (floating-point) with that rank.
*/
class TDIGESTBYRANK extends RedisCommand
{
public function getId()
{
return 'TDIGEST.BYRANK';
}
}
@@ -47,6 +47,14 @@ class TDIGESTADD_Test extends PredisCommandTestCase
$this->assertSameValues($expectedArguments, $command->getArguments());
}
/**
* @group disconnected
*/
public function testParseResponse(): void
{
$this->assertSame(1, $this->getCommand()->parseResponse(1));
}
/**
* @group connected
* @return void
@@ -0,0 +1,77 @@
<?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;
class TDIGESTBYRANK_Test extends PredisCommandTestCase
{
/**
* {@inheritDoc}
*/
protected function getExpectedCommand(): string
{
return TDIGESTBYRANK::class;
}
/**
* {@inheritDoc}
*/
protected function getExpectedId(): string
{
return 'TDIGESTBYRANK';
}
/**
* @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 testReturnsValuesEstimatedForGivenRanks(): void
{
$redis = $this->getClient();
$expectedResponse = ['1', '2', '2', '3', '3', '3', 'inf'];
$redis->tdigestcreate('key');
$redis->tdigestcreate('empty_key');
$redis->tdigestadd('key', 1, 2, 2, 3, 3, 3);
$actualResponse = $redis->tdigestbyrank('key', 0, 1, 2, 3, 4, 5, 6);
$this->assertSame($expectedResponse, $actualResponse);
$this->assertSame(['nan', 'nan'], $redis->tdigestbyrank('empty_key', 0, 1));
}
}