diff --git a/src/ClientContextInterface.php b/src/ClientContextInterface.php index 57089101..f489ddc2 100644 --- a/src/ClientContextInterface.php +++ b/src/ClientContextInterface.php @@ -179,6 +179,7 @@ use Predis\Command\CommandInterface; * @method $this tdigestcdf(string $key, int ...$value) * @method $this tdigestcreate(string $key, int $compression = 0) * @method $this tdigestinfo(string $key) + * @method $this tdigestmax(string $key) * @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 134d3284..edc5fa1f 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -189,6 +189,7 @@ use Predis\Response\Status; * @method array tdigestcdf(string $key, int ...$value) * @method Status tdigestcreate(string $key, int $compression = 0) * @method array tdigestinfo(string $key) + * @method string tdigestmax(string $key) * @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/TDIGESTMAX.php b/src/Command/Redis/TDigest/TDIGESTMAX.php new file mode 100644 index 00000000..5dc86410 --- /dev/null +++ b/src/Command/Redis/TDigest/TDIGESTMAX.php @@ -0,0 +1,28 @@ +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 testReturnsMaxValueFromGivenSketch(): void + { + $redis = $this->getClient(); + + $redis->tdigestcreate('key'); + $redis->tdigestcreate('empty_key'); + + $redis->tdigestadd('key', 3, 2, 4, 5, 1); + + $actualResponse = $redis->tdigestmax('key'); + + $this->assertSame('5', $actualResponse); + $this->assertSame('nan', $redis->tdigestmax('empty_key')); + } + + /** + * @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->tdigestmax('key'); + } +}