From 251f60435bbc524164ac5b0f522693d6925a2705 Mon Sep 17 00:00:00 2001 From: shacharPash <93581407+shacharPash@users.noreply.github.com> Date: Mon, 6 Feb 2023 14:48:39 +0200 Subject: [PATCH] Extended support by implementing TDIGEST.MIN command (#1100) * add support for CF.ADDNX * fix key name * fix wrong command * Pulling changes * Support TDIGEST.MIN --- src/ClientContextInterface.php | 1 + src/ClientInterface.php | 1 + src/Command/Redis/TDigest/TDIGESTMIN.php | 28 ++++++ .../Command/Redis/TDigest/TDIGESTMIN_Test.php | 92 +++++++++++++++++++ 4 files changed, 122 insertions(+) create mode 100644 src/Command/Redis/TDigest/TDIGESTMIN.php create mode 100644 tests/Predis/Command/Redis/TDigest/TDIGESTMIN_Test.php 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'); + } +}