diff --git a/src/ClientContextInterface.php b/src/ClientContextInterface.php index 8251f0d5..6e921280 100644 --- a/src/ClientContextInterface.php +++ b/src/ClientContextInterface.php @@ -175,6 +175,7 @@ use Predis\Command\CommandInterface; * @method $this sunionstore($destination, array|string $keys) * @method $this tdigestadd(string $key, float ...$value) * @method $this tdigestbyrank(string $key, int ...$rank) + * @method $this tdigestbyrevrank(string $key, int ...$reverseRank) * @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 c90a9ded..b7eb7ab8 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -185,6 +185,7 @@ use Predis\Response\Status; * @method int touch(string[]|string $keyOrKeys, string ...$keys = null) * @method Status tdigestadd(string $key, float ...$value) * @method array tdigestbyrank(string $key, int ...$rank) + * @method array tdigestbyrevrank(string $key, int ...$reverseRank) * @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/TDIGESTBYREVRANK.php b/src/Command/Redis/TDigest/TDIGESTBYREVRANK.php new file mode 100644 index 00000000..62322836 --- /dev/null +++ b/src/Command/Redis/TDigest/TDIGESTBYREVRANK.php @@ -0,0 +1,28 @@ +assertSame($expectedResponse, $actualResponse); $this->assertSame(['nan', 'nan'], $redis->tdigestbyrank('empty_key', 0, 1)); } + + /** + * @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->tdigestbyrank('key', 1, 2, 3); + } } diff --git a/tests/Predis/Command/Redis/TDigest/TDIGESTBYREVRANK_Test.php b/tests/Predis/Command/Redis/TDigest/TDIGESTBYREVRANK_Test.php new file mode 100644 index 00000000..c767ab19 --- /dev/null +++ b/tests/Predis/Command/Redis/TDigest/TDIGESTBYREVRANK_Test.php @@ -0,0 +1,93 @@ +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 testReturnsValuesEstimatedForGivenReverseRanks(): void + { + $redis = $this->getClient(); + $expectedResponse = ['3', '3', '3', '2', '2', '1', '-inf']; + + $redis->tdigestcreate('key'); + $redis->tdigestcreate('empty_key'); + + $redis->tdigestadd('key', 1, 2, 2, 3, 3, 3); + + $actualResponse = $redis->tdigestbyrevrank('key', 0, 1, 2, 3, 4, 5, 6); + + $this->assertSame($expectedResponse, $actualResponse); + $this->assertSame(['nan', 'nan'], $redis->tdigestbyrevrank('empty_key', 0, 1)); + } + + /** + * @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->tdigestbyrevrank('key', 1, 2, 3); + } +}