diff --git a/CHANGELOG.md b/CHANGELOG.md index 324628c7..431262ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Added support for `TS.READ` command - Added support for `EXCLUDEEMPTY` argument for `TS.MRANGE` and `TS.MREVRANGE` commands - Added explicit testing for FT.SEARCH timeout policies +- Added support for `TS.QUERYLABELS` command - Added support for `FT.ALIASLIST` command ### Fixed diff --git a/src/ClientContextInterface.php b/src/ClientContextInterface.php index 306fc07e..7fb82efe 100644 --- a/src/ClientContextInterface.php +++ b/src/ClientContextInterface.php @@ -316,6 +316,7 @@ use Predis\Command\Redis\VADD; * @method $this tsnrange(array $keys, $fromTimestamp, $toTimestamp, ?NRangeArguments $arguments = null) * @method $this tsnrevrange(array $keys, $fromTimestamp, $toTimestamp, ?NRangeArguments $arguments = null) * @method $this tsqueryindex(string ...$filterExpression) + * @method $this tsquerylabels(?string $label = null, string ...$filterExpression) * @method $this tsrange(string $key, $fromTimestamp, $toTimestamp, ?RangeArguments $arguments = null) * @method $this tsread(string $key, $timestamp, ?ReadArguments $arguments = null) * @method $this tsrevrange(string $key, $fromTimestamp, $toTimestamp, ?RangeArguments $arguments = null) diff --git a/src/ClientInterface.php b/src/ClientInterface.php index dd2ba66b..f8cfb4a5 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -328,6 +328,7 @@ use Predis\Response\Status; * @method array tsnrange(array $keys, $fromTimestamp, $toTimestamp, ?NRangeArguments $arguments = null) * @method array tsnrevrange(array $keys, $fromTimestamp, $toTimestamp, ?NRangeArguments $arguments = null) * @method array tsqueryindex(string ...$filterExpression) + * @method array tsquerylabels(?string $label = null, string ...$filterExpression) * @method array tsrange(string $key, $fromTimestamp, $toTimestamp, ?RangeArguments $arguments = null) * @method array tsread(string $key, $timestamp, ?ReadArguments $arguments = null) * @method array tsrevrange(string $key, $fromTimestamp, $toTimestamp, ?RangeArguments $arguments = null) diff --git a/src/Command/Redis/TimeSeries/TSQUERYLABELS.php b/src/Command/Redis/TimeSeries/TSQUERYLABELS.php new file mode 100644 index 00000000..aa3d7dfa --- /dev/null +++ b/src/Command/Redis/TimeSeries/TSQUERYLABELS.php @@ -0,0 +1,50 @@ +getCommand(); + $command->setArguments($actualArguments); + + $this->assertSameValues($expectedArguments, $command->getArguments()); + } + + /** + * @group connected + * @group relay-resp3 + * @return void + * @requiresRedisVersion >= 8.10.0 + */ + public function testQueryReturnsLabelNamesMatchingGivenFilterExpression(): void + { + $redis = $this->getClient(); + + $arguments = (new CreateArguments()) + ->labels('type', 'temp', 'location', 'TLV'); + + $this->assertEquals('OK', $redis->tscreate('temp:TLV', $arguments)); + + $anotherArguments = (new CreateArguments()) + ->labels('type', 'temp', 'location', 'JER'); + + $this->assertEquals('OK', $redis->tscreate('temp:JER', $anotherArguments)); + + $response = $redis->tsquerylabels(null, 'type=temp'); + sort($response); + + $this->assertSame(['location', 'type'], $response); + } + + /** + * @group connected + * @group relay-resp3 + * @return void + * @requiresRedisVersion >= 8.10.0 + */ + public function testQueryReturnsLabelValuesMatchingGivenFilterExpression(): void + { + $redis = $this->getClient(); + + $arguments = (new CreateArguments()) + ->labels('type', 'temp', 'location', 'TLV'); + + $this->assertEquals('OK', $redis->tscreate('temp:TLV', $arguments)); + + $anotherArguments = (new CreateArguments()) + ->labels('type', 'temp', 'location', 'JER'); + + $this->assertEquals('OK', $redis->tscreate('temp:JER', $anotherArguments)); + + $response = $redis->tsquerylabels('location', 'type=temp'); + sort($response); + + $this->assertSame(['JER', 'TLV'], $response); + } + + /** + * @group connected + * @return void + * @requiresRedisVersion >= 8.10.0 + */ + public function testQueryReturnsLabelNamesMatchingGivenFilterExpressionResp3(): void + { + $redis = $this->getResp3Client(); + + $arguments = (new CreateArguments()) + ->labels('type', 'temp', 'location', 'TLV'); + + $this->assertEquals('OK', $redis->tscreate('temp:TLV', $arguments)); + + $anotherArguments = (new CreateArguments()) + ->labels('type', 'temp', 'location', 'JER'); + + $this->assertEquals('OK', $redis->tscreate('temp:JER', $anotherArguments)); + + $response = $redis->tsquerylabels(null, 'type=temp'); + sort($response); + + $this->assertSame(['location', 'type'], $response); + } + + /** + * @group connected + * @return void + * @requiresRedisVersion >= 8.10.0 + */ + public function testQueryReturnsLabelValuesMatchingGivenFilterExpressionResp3(): void + { + $redis = $this->getResp3Client(); + + $arguments = (new CreateArguments()) + ->labels('type', 'temp', 'location', 'TLV'); + + $this->assertEquals('OK', $redis->tscreate('temp:TLV', $arguments)); + + $anotherArguments = (new CreateArguments()) + ->labels('type', 'temp', 'location', 'JER'); + + $this->assertEquals('OK', $redis->tscreate('temp:JER', $anotherArguments)); + + $response = $redis->tsquerylabels('location', 'type=temp'); + sort($response); + + $this->assertSame(['JER', 'TLV'], $response); + } + + public function argumentsProvider(): array + { + return [ + 'with no arguments' => [ + [], + ['LABELS'], + ], + 'with null label' => [ + [null], + ['LABELS'], + ], + 'with null label and filter expressions' => [ + [null, 'type=temp', 'location!='], + ['LABELS', 'FILTER', 'type=temp', 'location!='], + ], + 'with label' => [ + ['location'], + ['VALUES', 'location'], + ], + 'with label and filter expressions' => [ + ['location', 'type=temp', 'location!='], + ['VALUES', 'location', 'FILTER', 'type=temp', 'location!='], + ], + ]; + } +}