diff --git a/src/ClientContextInterface.php b/src/ClientContextInterface.php index c7538104..6c7bd8c2 100644 --- a/src/ClientContextInterface.php +++ b/src/ClientContextInterface.php @@ -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) diff --git a/src/ClientInterface.php b/src/ClientInterface.php index 8c6e3dfb..60a6040f 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -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) diff --git a/src/Command/Redis/TDigest/TDIGESTREVRANK.php b/src/Command/Redis/TDigest/TDIGESTREVRANK.php new file mode 100644 index 00000000..dec77803 --- /dev/null +++ b/src/Command/Redis/TDigest/TDIGESTREVRANK.php @@ -0,0 +1,30 @@ +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); + } +}