diff --git a/src/ClientContextInterface.php b/src/ClientContextInterface.php index 8877d38c..4fe56a4c 100644 --- a/src/ClientContextInterface.php +++ b/src/ClientContextInterface.php @@ -181,6 +181,7 @@ use Predis\Command\CommandInterface; * @method $this tdigestinfo(string $key) * @method $this tdigestmax(string $key) * @method $this tdigestmin(string $key) + * @method $this tdigestrank(string $key, ...$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 9d831478..afffa298 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -191,6 +191,7 @@ use Predis\Response\Status; * @method array tdigestinfo(string $key) * @method string tdigestmax(string $key) * @method string tdigestmin(string $key) + * @method array tdigestrank(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/TDIGESTRANK.php b/src/Command/Redis/TDigest/TDIGESTRANK.php new file mode 100644 index 00000000..3e41db1e --- /dev/null +++ b/src/Command/Redis/TDigest/TDIGESTRANK.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 testReturnsRankOfGivenObservationValue(): void + { + $redis = $this->getClient(); + $expectedResponse = [-1, 0, 1, 2, 3]; + + $redis->tdigestcreate('key'); + $redis->tdigestcreate('empty_key'); + + $redis->tdigestadd('key', 10, 20, 30); + + $actualResponse = $redis->tdigestrank('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->tdigestrank('key', 1, 2, 3); + } +}