diff --git a/src/ClientContextInterface.php b/src/ClientContextInterface.php index cf490c93..8251f0d5 100644 --- a/src/ClientContextInterface.php +++ b/src/ClientContextInterface.php @@ -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) diff --git a/src/ClientInterface.php b/src/ClientInterface.php index 827c2f25..c90a9ded 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -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) diff --git a/src/Command/Redis/TDigest/TDIGESTBYRANK.php b/src/Command/Redis/TDigest/TDIGESTBYRANK.php new file mode 100644 index 00000000..a8b8d482 --- /dev/null +++ b/src/Command/Redis/TDigest/TDIGESTBYRANK.php @@ -0,0 +1,28 @@ +assertSameValues($expectedArguments, $command->getArguments()); } + /** + * @group disconnected + */ + public function testParseResponse(): void + { + $this->assertSame(1, $this->getCommand()->parseResponse(1)); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TDigest/TDIGESTBYRANK_Test.php b/tests/Predis/Command/Redis/TDigest/TDIGESTBYRANK_Test.php new file mode 100644 index 00000000..750e452f --- /dev/null +++ b/tests/Predis/Command/Redis/TDigest/TDIGESTBYRANK_Test.php @@ -0,0 +1,77 @@ +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)); + } +}