diff --git a/src/ClientContextInterface.php b/src/ClientContextInterface.php index f3dd2ba6..cf490c93 100644 --- a/src/ClientContextInterface.php +++ b/src/ClientContextInterface.php @@ -173,6 +173,7 @@ use Predis\Command\CommandInterface; * @method $this sscan($key, $cursor, array $options = null) * @method $this sunion(array|string $keys) * @method $this sunionstore($destination, array|string $keys) + * @method $this tdigestadd(string $key, float ...$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 52881117..827c2f25 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -183,6 +183,7 @@ use Predis\Response\Status; * @method string[] sunion(array|string $keys) * @method int sunionstore(string $destination, array|string $keys) * @method int touch(string[]|string $keyOrKeys, string ...$keys = null) + * @method Status tdigestadd(string $key, float ...$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/TDIGESTADD.php b/src/Command/Redis/TDigest/TDIGESTADD.php new file mode 100644 index 00000000..0ef789e3 --- /dev/null +++ b/src/Command/Redis/TDigest/TDIGESTADD.php @@ -0,0 +1,28 @@ +getCommand(); + $command->setArguments($actualArguments); + + $this->assertSameValues($expectedArguments, $command->getArguments()); + } + + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.4.0 + */ + public function testAddObservationsIntoGivenTDigestSketch(): void + { + $redis = $this->getClient(); + + $redis->tdigestcreate('key'); + + $actualResponse = $redis->tdigestadd('key', 1, 2, 3); + $info = $redis->tdigestinfo('key'); + + $this->assertEquals('OK', $actualResponse); + $this->assertSame(3, $info['Observations']); + } + + /** + * @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->tdigestadd('key', 1, 2, 3); + } +}