diff --git a/src/ClientContextInterface.php b/src/ClientContextInterface.php index f489ddc2..8877d38c 100644 --- a/src/ClientContextInterface.php +++ b/src/ClientContextInterface.php @@ -180,6 +180,7 @@ use Predis\Command\CommandInterface; * @method $this tdigestcreate(string $key, int $compression = 0) * @method $this tdigestinfo(string $key) * @method $this tdigestmax(string $key) + * @method $this tdigestmin(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 edc5fa1f..9d831478 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -190,6 +190,7 @@ use Predis\Response\Status; * @method Status tdigestcreate(string $key, int $compression = 0) * @method array tdigestinfo(string $key) * @method string tdigestmax(string $key) + * @method string tdigestmin(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/TDIGESTMIN.php b/src/Command/Redis/TDigest/TDIGESTMIN.php new file mode 100644 index 00000000..d997c841 --- /dev/null +++ b/src/Command/Redis/TDigest/TDIGESTMIN.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 testReturnsMinValueFromGivenSketch(): void + { + $redis = $this->getClient(); + + $redis->tdigestcreate('key'); + $redis->tdigestcreate('empty_key'); + + $redis->tdigestadd('key', 3, 2, 4, 5, 1); + + $actualResponse = $redis->tdigestmin('key'); + + $this->assertSame('1', $actualResponse); + $this->assertSame('nan', $redis->tdigestmin('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->tdigestmin('key'); + } +}