diff --git a/src/ClientContextInterface.php b/src/ClientContextInterface.php index 6e921280..57089101 100644 --- a/src/ClientContextInterface.php +++ b/src/ClientContextInterface.php @@ -176,6 +176,7 @@ use Predis\Command\CommandInterface; * @method $this tdigestadd(string $key, float ...$value) * @method $this tdigestbyrank(string $key, int ...$rank) * @method $this tdigestbyrevrank(string $key, int ...$reverseRank) + * @method $this tdigestcdf(string $key, int ...$value) * @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 b7eb7ab8..134d3284 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -186,6 +186,7 @@ use Predis\Response\Status; * @method Status tdigestadd(string $key, float ...$value) * @method array tdigestbyrank(string $key, int ...$rank) * @method array tdigestbyrevrank(string $key, int ...$reverseRank) + * @method array tdigestcdf(string $key, int ...$value) * @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/TDIGESTCDF.php b/src/Command/Redis/TDigest/TDIGESTCDF.php new file mode 100644 index 00000000..42aaefb4 --- /dev/null +++ b/src/Command/Redis/TDigest/TDIGESTCDF.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 testReturnsValuesEstimatedForGivenRanks(): void + { + $redis = $this->getClient(); + $expectedResponse = ['0', '0.083333333333333329', '0.33333333333333331', '0.75', '1']; + + $redis->tdigestcreate('key'); + $redis->tdigestcreate('empty_key'); + + $redis->tdigestadd('key', 1, 2, 2, 3, 3, 3); + + $actualResponse = $redis->tdigestcdf('key', 0, 1, 2, 3, 4); + + $this->assertSame($expectedResponse, $actualResponse); + $this->assertSame(['nan', 'nan'], $redis->tdigestcdf('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->tdigestcdf('key', 1, 2, 3); + } +}