diff --git a/src/ClientContextInterface.php b/src/ClientContextInterface.php index 4fe56a4c..496acdb0 100644 --- a/src/ClientContextInterface.php +++ b/src/ClientContextInterface.php @@ -182,6 +182,7 @@ use Predis\Command\CommandInterface; * @method $this tdigestmax(string $key) * @method $this tdigestmin(string $key) * @method $this tdigestrank(string $key, ...$value) + * @method $this tdigestreset(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 afffa298..d1bd3c56 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -192,6 +192,7 @@ use Predis\Response\Status; * @method string tdigestmax(string $key) * @method string tdigestmin(string $key) * @method array tdigestrank(string $key, float ...$value) + * @method Status tdigestreset(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/TDIGESTRESET.php b/src/Command/Redis/TDigest/TDIGESTRESET.php new file mode 100644 index 00000000..0456f4f9 --- /dev/null +++ b/src/Command/Redis/TDigest/TDIGESTRESET.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 testResetExistingSketch(): void + { + $redis = $this->getClient(); + + $redis->tdigestcreate('key', 500); + $redis->tdigestadd('key', 1, 2, 2, 3, 3, 3); + + $this->assertSame( + ['1', '2', '2', '3', '3', '3'], + $redis->tdigestbyrank('key', 0, 1, 2, 3, 4, 5) + ); + + $actualResponse = $redis->tdigestreset('key'); + $info = $redis->tdigestinfo('key'); + + $this->assertEquals('OK', $actualResponse); + $this->assertSame(500, $info['Compression']); + $this->assertSame( + ['nan', 'nan', 'nan', 'nan', 'nan', 'nan'], + $redis->tdigestbyrank('key', 0, 1, 2, 3, 4, 5) + ); + } + + /** + * @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->tdigestreset('key'); + } +}