diff --git a/examples/Commands/TimeSeries/ts_add.php b/examples/Commands/TimeSeries/ts_add.php index c4713f09..0f7e28aa 100644 --- a/examples/Commands/TimeSeries/ts_add.php +++ b/examples/Commands/TimeSeries/ts_add.php @@ -23,7 +23,7 @@ require __DIR__ . '/../../shared.php'; $client = new Client(); $arguments = (new CreateArguments()) - ->retention(60000) + ->retentionMsecs(60000) ->duplicatePolicy(CommonArguments::POLICY_MAX) ->labels('sensor_id', 2, 'area_id', 32); @@ -31,7 +31,7 @@ $client->tscreate('temperature:2:32', $arguments); // 2. Add sample into newly created time series $addArguments = (new AddArguments()) - ->retention(31536000000); + ->retentionMsecs(31536000000); $response = $client->tsadd('temperature:2:32', 123123123123, 27, $addArguments); diff --git a/examples/Commands/TimeSeries/ts_alter.php b/examples/Commands/TimeSeries/ts_alter.php index fa64dfb9..5e06c152 100644 --- a/examples/Commands/TimeSeries/ts_alter.php +++ b/examples/Commands/TimeSeries/ts_alter.php @@ -23,7 +23,7 @@ require __DIR__ . '/../../shared.php'; $client = new Client(); $arguments = (new CreateArguments()) - ->retention(60000) + ->retentionMsecs(60000) ->duplicatePolicy(CommonArguments::POLICY_MAX) ->labels('sensor_id', 2, 'area_id', 32); diff --git a/examples/Commands/TimeSeries/ts_create.php b/examples/Commands/TimeSeries/ts_create.php index e03d4c09..989d1e13 100644 --- a/examples/Commands/TimeSeries/ts_create.php +++ b/examples/Commands/TimeSeries/ts_create.php @@ -22,7 +22,7 @@ require __DIR__ . '/../../shared.php'; $client = new Client(); $arguments = (new CreateArguments()) - ->retention(60000) + ->retentionMsecs(60000) ->duplicatePolicy(CommonArguments::POLICY_MAX) ->labels('sensor_id', 2, 'area_id', 32); diff --git a/examples/Commands/TimeSeries/ts_decrby.php b/examples/Commands/TimeSeries/ts_decrby.php index 80862c67..a3e85d4e 100644 --- a/examples/Commands/TimeSeries/ts_decrby.php +++ b/examples/Commands/TimeSeries/ts_decrby.php @@ -24,7 +24,7 @@ require __DIR__ . '/../../shared.php'; $client = new Client(); $arguments = (new CreateArguments()) - ->retention(60000) + ->retentionMsecs(60000) ->duplicatePolicy(CommonArguments::POLICY_MAX) ->labels('sensor_id', 2, 'area_id', 32); @@ -32,7 +32,7 @@ $client->tscreate('temperature:2:32', $arguments); // 2. Add sample into newly created time series $addArguments = (new AddArguments()) - ->retention(31536000000); + ->retentionMsecs(31536000000); $response = $client->tsadd('temperature:2:32', 123123123123, 27, $addArguments); diff --git a/examples/Commands/TimeSeries/ts_del.php b/examples/Commands/TimeSeries/ts_del.php index 42ed0838..009ab57c 100644 --- a/examples/Commands/TimeSeries/ts_del.php +++ b/examples/Commands/TimeSeries/ts_del.php @@ -21,7 +21,7 @@ require __DIR__ . '/../../shared.php'; $client = new Client(); $arguments = (new CreateArguments()) - ->retention(60000) + ->retentionMsecs(60000) ->duplicatePolicy(CommonArguments::POLICY_MAX) ->labels('sensor_id', 2, 'area_id', 32); diff --git a/examples/Commands/TimeSeries/ts_get.php b/examples/Commands/TimeSeries/ts_get.php index aa1b065b..737b984f 100644 --- a/examples/Commands/TimeSeries/ts_get.php +++ b/examples/Commands/TimeSeries/ts_get.php @@ -21,7 +21,7 @@ require __DIR__ . '/../../shared.php'; $client = new Client(); $arguments = (new CreateArguments()) - ->retention(60000) + ->retentionMsecs(60000) ->duplicatePolicy(CommonArguments::POLICY_MAX) ->labels('sensor_id', 2, 'area_id', 32); diff --git a/examples/Commands/TimeSeries/ts_incrby.php b/examples/Commands/TimeSeries/ts_incrby.php index 49f7a812..2905d124 100644 --- a/examples/Commands/TimeSeries/ts_incrby.php +++ b/examples/Commands/TimeSeries/ts_incrby.php @@ -24,7 +24,7 @@ require __DIR__ . '/../../shared.php'; $client = new Client(); $arguments = (new CreateArguments()) - ->retention(60000) + ->retentionMsecs(60000) ->duplicatePolicy(CommonArguments::POLICY_MAX) ->labels('sensor_id', 2, 'area_id', 32); @@ -32,7 +32,7 @@ $client->tscreate('temperature:2:32', $arguments); // 2. Add sample into newly created time series $addArguments = (new AddArguments()) - ->retention(31536000000); + ->retentionMsecs(31536000000); $response = $client->tsadd('temperature:2:32', 123123123123, 27, $addArguments); diff --git a/examples/Commands/TimeSeries/ts_info.php b/examples/Commands/TimeSeries/ts_info.php new file mode 100644 index 00000000..66c52b23 --- /dev/null +++ b/examples/Commands/TimeSeries/ts_info.php @@ -0,0 +1,32 @@ +retentionMsecs(60000) + ->duplicatePolicy(CommonArguments::POLICY_MAX) + ->labels('sensor_id', 2, 'area_id', 32); + +$client->tscreate('temperature:2:32', $arguments); + +// 2. Show info about given time series +print_r($client->tsinfo('temperature:2:32')); diff --git a/examples/Commands/TimeSeries/ts_madd.php b/examples/Commands/TimeSeries/ts_madd.php index 606c4f16..23a0336a 100644 --- a/examples/Commands/TimeSeries/ts_madd.php +++ b/examples/Commands/TimeSeries/ts_madd.php @@ -22,7 +22,7 @@ require __DIR__ . '/../../shared.php'; $client = new Client(); $arguments = (new CreateArguments()) - ->retention(60000) + ->retentionMsecs(60000) ->duplicatePolicy(CommonArguments::POLICY_MAX) ->labels('sensor_id', 2, 'area_id', 32); diff --git a/examples/Commands/TimeSeries/ts_mget.php b/examples/Commands/TimeSeries/ts_mget.php index fc3df170..eb3720d7 100644 --- a/examples/Commands/TimeSeries/ts_mget.php +++ b/examples/Commands/TimeSeries/ts_mget.php @@ -23,7 +23,7 @@ require __DIR__ . '/../../shared.php'; $client = new Client(); $arguments = (new CreateArguments()) - ->retention(60000) + ->retentionMsecs(60000) ->duplicatePolicy(CommonArguments::POLICY_MAX) ->labels('type', 'temp', 'sensor_id', 2, 'area_id', 32); diff --git a/src/ClientContextInterface.php b/src/ClientContextInterface.php index d1aef2d4..5a7d8f6a 100644 --- a/src/ClientContextInterface.php +++ b/src/ClientContextInterface.php @@ -33,6 +33,7 @@ use Predis\Command\Argument\TimeSeries\CreateArguments as TSCreateArguments; use Predis\Command\Argument\TimeSeries\DecrByArguments; use Predis\Command\Argument\TimeSeries\GetArguments; use Predis\Command\Argument\TimeSeries\IncrByArguments; +use Predis\Command\Argument\TimeSeries\InfoArguments; use Predis\Command\Argument\TimeSeries\MGetArguments; use Predis\Command\CommandInterface; use Predis\Command\Container\FUNCTIONS; @@ -246,6 +247,7 @@ use Predis\Command\Container\Search\FTCONFIG; * @method $this tsdel(string $key, int $fromTimestamp, int $toTimestamp) * @method $this tsget(string $key, GetArguments $arguments = null) * @method $this tsincrby(string $key, float $value, ?IncrByArguments $arguments = null) + * @method $this tsinfo(string $key, ?InfoArguments $arguments = null) * @method $this tsmadd(mixed ...$keyTimestampValue) * @method $this tsmget(MGetArguments $arguments, string ...$filterExpression) * @method $this zadd($key, array $membersAndScoresDictionary) diff --git a/src/ClientInterface.php b/src/ClientInterface.php index f7590634..1418bd3c 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -33,6 +33,7 @@ use Predis\Command\Argument\TimeSeries\CreateArguments as TSCreateArguments; use Predis\Command\Argument\TimeSeries\DecrByArguments; use Predis\Command\Argument\TimeSeries\GetArguments; use Predis\Command\Argument\TimeSeries\IncrByArguments; +use Predis\Command\Argument\TimeSeries\InfoArguments; use Predis\Command\Argument\TimeSeries\MGetArguments; use Predis\Command\CommandInterface; use Predis\Command\Container\FUNCTIONS; @@ -256,6 +257,7 @@ use Predis\Response\Status; * @method int tsdel(string $key, int $fromTimestamp, int $toTimestamp) * @method array tsget(string $key, GetArguments $arguments = null) * @method int tsincrby(string $key, float $value, ?IncrByArguments $arguments = null) + * @method array tsinfo(string $key, ?InfoArguments $arguments = null) * @method array tsmadd(mixed ...$keyTimestampValue) * @method array tsmget(MGetArguments $arguments, string ...$filterExpression) * @method string xadd(string $key, array $dictionary, string $id = '*', array $options = null) diff --git a/src/Command/Argument/TimeSeries/CommonArguments.php b/src/Command/Argument/TimeSeries/CommonArguments.php index b15d5dd4..d70b841f 100644 --- a/src/Command/Argument/TimeSeries/CommonArguments.php +++ b/src/Command/Argument/TimeSeries/CommonArguments.php @@ -37,7 +37,7 @@ class CommonArguments implements ArrayableArgument * @param int $retentionPeriod * @return $this */ - public function retention(int $retentionPeriod): self + public function retentionMsecs(int $retentionPeriod): self { array_push($this->arguments, 'RETENTION', $retentionPeriod); diff --git a/src/Command/Argument/TimeSeries/InfoArguments.php b/src/Command/Argument/TimeSeries/InfoArguments.php new file mode 100644 index 00000000..1b2cec66 --- /dev/null +++ b/src/Command/Argument/TimeSeries/InfoArguments.php @@ -0,0 +1,43 @@ +arguments[] = 'DEBUG'; + + return $this; + } + + /** + * {@inheritDoc} + */ + public function toArray(): array + { + return $this->arguments; + } +} diff --git a/src/Command/Redis/TimeSeries/TSINFO.php b/src/Command/Redis/TimeSeries/TSINFO.php new file mode 100644 index 00000000..d4941d40 --- /dev/null +++ b/src/Command/Redis/TimeSeries/TSINFO.php @@ -0,0 +1,39 @@ +toArray() : []; + + parent::setArguments(array_merge( + [$key], + $commandArguments + )); + } +} diff --git a/tests/Predis/Command/Argument/TimeSeries/CommonArgumentsTest.php b/tests/Predis/Command/Argument/TimeSeries/CommonArgumentsTest.php index 88ecb334..51d6ec14 100644 --- a/tests/Predis/Command/Argument/TimeSeries/CommonArgumentsTest.php +++ b/tests/Predis/Command/Argument/TimeSeries/CommonArgumentsTest.php @@ -31,7 +31,7 @@ class CommonArgumentsTest extends TestCase */ public function testCreatesArgumentsWithRetentionModifier(): void { - $this->arguments->retention(10); + $this->arguments->retentionMsecs(10); $this->assertSame(['RETENTION', 10], $this->arguments->toArray()); } diff --git a/tests/Predis/Command/Argument/TimeSeries/InfoArgumentsTest.php b/tests/Predis/Command/Argument/TimeSeries/InfoArgumentsTest.php new file mode 100644 index 00000000..f41eb10f --- /dev/null +++ b/tests/Predis/Command/Argument/TimeSeries/InfoArgumentsTest.php @@ -0,0 +1,38 @@ +arguments = new InfoArguments(); + } + + /** + * @return void + */ + public function testCreatesArgumentsWithDebugModifier(): void + { + $this->arguments->debug(); + + $this->assertSame(['DEBUG'], $this->arguments->toArray()); + } +} diff --git a/tests/Predis/Command/Redis/TimeSeries/TSADD_Test.php b/tests/Predis/Command/Redis/TimeSeries/TSADD_Test.php index cec42a56..c4db6892 100644 --- a/tests/Predis/Command/Redis/TimeSeries/TSADD_Test.php +++ b/tests/Predis/Command/Redis/TimeSeries/TSADD_Test.php @@ -65,7 +65,7 @@ class TSADD_Test extends PredisCommandTestCase $redis = $this->getClient(); $createArguments = (new CreateArguments()) - ->retention(60000) + ->retentionMsecs(60000) ->duplicatePolicy(CommonArguments::POLICY_MAX) ->labels('sensor_id', 2, 'area_id', 32); @@ -75,7 +75,7 @@ class TSADD_Test extends PredisCommandTestCase ); $addArguments = (new AddArguments()) - ->retention(31536000000); + ->retentionMsecs(31536000000); $this->assertEquals( 123123123123, @@ -91,7 +91,7 @@ class TSADD_Test extends PredisCommandTestCase ['key', 123123121321, 1.0], ], 'with RETENTION modifier' => [ - ['key', 123123121321, 1.0, (new AddArguments())->retention(100)], + ['key', 123123121321, 1.0, (new AddArguments())->retentionMsecs(100)], ['key', 123123121321, 1.0, 'RETENTION', 100], ], 'with ENCODING modifier' => [ @@ -107,7 +107,7 @@ class TSADD_Test extends PredisCommandTestCase ['key', 123123121321, 1.0, 'ON_DUPLICATE', CommonArguments::POLICY_FIRST], ], 'with all modifiers' => [ - ['key', 123123121321, 1.0, (new AddArguments())->retention(100)->encoding(CommonArguments::ENCODING_UNCOMPRESSED)->chunkSize(100)->onDuplicate(CommonArguments::POLICY_FIRST)], + ['key', 123123121321, 1.0, (new AddArguments())->retentionMsecs(100)->encoding(CommonArguments::ENCODING_UNCOMPRESSED)->chunkSize(100)->onDuplicate(CommonArguments::POLICY_FIRST)], ['key', 123123121321, 1.0, 'RETENTION', 100, 'ENCODING', CommonArguments::ENCODING_UNCOMPRESSED, 'CHUNK_SIZE', 100, 'ON_DUPLICATE', CommonArguments::POLICY_FIRST], ], ]; diff --git a/tests/Predis/Command/Redis/TimeSeries/TSALTER_Test.php b/tests/Predis/Command/Redis/TimeSeries/TSALTER_Test.php index d59e62b5..e8c5db63 100644 --- a/tests/Predis/Command/Redis/TimeSeries/TSALTER_Test.php +++ b/tests/Predis/Command/Redis/TimeSeries/TSALTER_Test.php @@ -66,7 +66,7 @@ class TSALTER_Test extends PredisCommandTestCase $redis = $this->getClient(); $arguments = (new CreateArguments()) - ->retention(60000) + ->retentionMsecs(60000) ->duplicatePolicy(CommonArguments::POLICY_MAX) ->labels('sensor_id', 2, 'area_id', 32); @@ -76,7 +76,7 @@ class TSALTER_Test extends PredisCommandTestCase ); $alterArguments = (new AlterArguments()) - ->retention(10000000); + ->retentionMsecs(10000000); $this->assertEquals( 'OK', @@ -107,7 +107,7 @@ class TSALTER_Test extends PredisCommandTestCase ['key'], ], 'with RETENTION modifier' => [ - ['key', (new AlterArguments())->retention(100)], + ['key', (new AlterArguments())->retentionMsecs(100)], ['key', 'RETENTION', 100], ], 'with CHUNK_SIZE modifier' => [ @@ -119,7 +119,7 @@ class TSALTER_Test extends PredisCommandTestCase ['key', 'DUPLICATE_POLICY', CommonArguments::POLICY_FIRST], ], 'with all modifiers' => [ - ['key', (new AlterArguments())->retention(100)->chunkSize(100)->duplicatePolicy(CommonArguments::POLICY_FIRST)], + ['key', (new AlterArguments())->retentionMsecs(100)->chunkSize(100)->duplicatePolicy(CommonArguments::POLICY_FIRST)], ['key', 'RETENTION', 100, 'CHUNK_SIZE', 100, 'DUPLICATE_POLICY', CommonArguments::POLICY_FIRST], ], ]; diff --git a/tests/Predis/Command/Redis/TimeSeries/TSCREATE_Test.php b/tests/Predis/Command/Redis/TimeSeries/TSCREATE_Test.php index 9d811167..62409d42 100644 --- a/tests/Predis/Command/Redis/TimeSeries/TSCREATE_Test.php +++ b/tests/Predis/Command/Redis/TimeSeries/TSCREATE_Test.php @@ -15,6 +15,7 @@ namespace Predis\Command\Redis\TimeSeries; use Predis\Command\Argument\TimeSeries\CommonArguments; use Predis\Command\Argument\TimeSeries\CreateArguments; use Predis\Command\Redis\PredisCommandTestCase; +use Predis\Response\ServerException; class TSCREATE_Test extends PredisCommandTestCase { @@ -64,7 +65,7 @@ class TSCREATE_Test extends PredisCommandTestCase $redis = $this->getClient(); $arguments = (new CreateArguments()) - ->retention(60000) + ->retentionMsecs(60000) ->duplicatePolicy(CommonArguments::POLICY_MAX) ->labels('sensor_id', 2, 'area_id', 32); @@ -74,6 +75,21 @@ class TSCREATE_Test extends PredisCommandTestCase ); } + /** + * @group connected + * @return void + * @requiresRedisTimeSeriesVersion >= 1.0.0 + */ + public function testThrowsExceptionOnNonExistingKey(): void + { + $redis = $this->getClient(); + + $this->expectException(ServerException::class); + $this->expectExceptionMessage('ERR TSDB: the key does not exist'); + + $redis->tsinfo('non_existing_key'); + } + public function argumentsProvider(): array { return [ @@ -82,7 +98,7 @@ class TSCREATE_Test extends PredisCommandTestCase ['key'], ], 'with RETENTION modifier' => [ - ['key', (new CreateArguments())->retention(100)], + ['key', (new CreateArguments())->retentionMsecs(100)], ['key', 'RETENTION', 100], ], 'with ENCODING modifier' => [ @@ -98,7 +114,7 @@ class TSCREATE_Test extends PredisCommandTestCase ['key', 'DUPLICATE_POLICY', CommonArguments::POLICY_FIRST], ], 'with all modifiers' => [ - ['key', (new CreateArguments())->retention(100)->encoding(CreateArguments::ENCODING_UNCOMPRESSED)->chunkSize(100)->duplicatePolicy(CommonArguments::POLICY_FIRST)], + ['key', (new CreateArguments())->retentionMsecs(100)->encoding(CreateArguments::ENCODING_UNCOMPRESSED)->chunkSize(100)->duplicatePolicy(CommonArguments::POLICY_FIRST)], ['key', 'RETENTION', 100, 'ENCODING', CreateArguments::ENCODING_UNCOMPRESSED, 'CHUNK_SIZE', 100, 'DUPLICATE_POLICY', CommonArguments::POLICY_FIRST], ], ]; diff --git a/tests/Predis/Command/Redis/TimeSeries/TSDECRBY_Test.php b/tests/Predis/Command/Redis/TimeSeries/TSDECRBY_Test.php index 5c792c9b..b99888a7 100644 --- a/tests/Predis/Command/Redis/TimeSeries/TSDECRBY_Test.php +++ b/tests/Predis/Command/Redis/TimeSeries/TSDECRBY_Test.php @@ -67,7 +67,7 @@ class TSDECRBY_Test extends PredisCommandTestCase $redis = $this->getClient(); $arguments = (new CreateArguments()) - ->retention(60000) + ->retentionMsecs(60000) ->duplicatePolicy(CommonArguments::POLICY_MAX) ->labels('sensor_id', 2, 'area_id', 32); @@ -77,7 +77,7 @@ class TSDECRBY_Test extends PredisCommandTestCase ); $addArguments = (new AddArguments()) - ->retention(31536000000); + ->retentionMsecs(31536000000); $this->assertEquals( 123123123123, @@ -100,7 +100,7 @@ class TSDECRBY_Test extends PredisCommandTestCase $redis = $this->getClient(); $arguments = (new CreateArguments()) - ->retention(60000) + ->retentionMsecs(60000) ->duplicatePolicy(CommonArguments::POLICY_MAX) ->labels('sensor_id', 2, 'area_id', 32); @@ -125,7 +125,7 @@ class TSDECRBY_Test extends PredisCommandTestCase $redis = $this->getClient(); $arguments = (new CreateArguments()) - ->retention(60000) + ->retentionMsecs(60000) ->duplicatePolicy(CommonArguments::POLICY_MAX) ->labels('sensor_id', 2, 'area_id', 32); @@ -135,7 +135,7 @@ class TSDECRBY_Test extends PredisCommandTestCase ); $addArguments = (new AddArguments()) - ->retention(31536000000); + ->retentionMsecs(31536000000); $this->assertEquals( 123123123123, @@ -160,7 +160,7 @@ class TSDECRBY_Test extends PredisCommandTestCase ['key', 1.0, 'TIMESTAMP', 10], ], 'with RETENTION modifier' => [ - ['key', 1.0, (new DecrByArguments())->retention(100)], + ['key', 1.0, (new DecrByArguments())->retentionMsecs(100)], ['key', 1.0, 'RETENTION', 100], ], 'with UNCOMPRESSED modifier' => [ @@ -176,7 +176,7 @@ class TSDECRBY_Test extends PredisCommandTestCase ['key', 1.0, 'LABELS', 'label1', 1, 'label2', 2], ], 'with all modifiers' => [ - ['key', 1.0, (new DecrByArguments())->timestamp(10)->retention(100)->uncompressed()->chunkSize(100)->labels('label1', 1, 'label2', 2)], + ['key', 1.0, (new DecrByArguments())->timestamp(10)->retentionMsecs(100)->uncompressed()->chunkSize(100)->labels('label1', 1, 'label2', 2)], ['key', 1.0, 'TIMESTAMP', 10, 'RETENTION', 100, 'UNCOMPRESSED', 'CHUNK_SIZE', 100, 'LABELS', 'label1', 1, 'label2', 2], ], ]; diff --git a/tests/Predis/Command/Redis/TimeSeries/TSDEL_Test.php b/tests/Predis/Command/Redis/TimeSeries/TSDEL_Test.php index 8884b6be..671f44ce 100644 --- a/tests/Predis/Command/Redis/TimeSeries/TSDEL_Test.php +++ b/tests/Predis/Command/Redis/TimeSeries/TSDEL_Test.php @@ -67,7 +67,7 @@ class TSDEL_Test extends PredisCommandTestCase $redis = $this->getClient(); $createArguments = (new CreateArguments()) - ->retention(60000) + ->retentionMsecs(60000) ->duplicatePolicy(CommonArguments::POLICY_MAX) ->labels('sensor_id', 2, 'area_id', 32); diff --git a/tests/Predis/Command/Redis/TimeSeries/TSGET_Test.php b/tests/Predis/Command/Redis/TimeSeries/TSGET_Test.php index 6fb9a920..099a9f28 100644 --- a/tests/Predis/Command/Redis/TimeSeries/TSGET_Test.php +++ b/tests/Predis/Command/Redis/TimeSeries/TSGET_Test.php @@ -66,7 +66,7 @@ class TSGET_Test extends PredisCommandTestCase $redis = $this->getClient(); $createArguments = (new CreateArguments()) - ->retention(60000) + ->retentionMsecs(60000) ->duplicatePolicy(CommonArguments::POLICY_MAX) ->labels('sensor_id', 2, 'area_id', 32); diff --git a/tests/Predis/Command/Redis/TimeSeries/TSINCRBY_Test.php b/tests/Predis/Command/Redis/TimeSeries/TSINCRBY_Test.php index 0f8044c2..95add6c9 100644 --- a/tests/Predis/Command/Redis/TimeSeries/TSINCRBY_Test.php +++ b/tests/Predis/Command/Redis/TimeSeries/TSINCRBY_Test.php @@ -67,7 +67,7 @@ class TSINCRBY_Test extends PredisCommandTestCase $redis = $this->getClient(); $arguments = (new CreateArguments()) - ->retention(60000) + ->retentionMsecs(60000) ->duplicatePolicy(CommonArguments::POLICY_MAX) ->labels('sensor_id', 2, 'area_id', 32); @@ -77,7 +77,7 @@ class TSINCRBY_Test extends PredisCommandTestCase ); $addArguments = (new AddArguments()) - ->retention(31536000000); + ->retentionMsecs(31536000000); $this->assertEquals( 123123123123, @@ -100,7 +100,7 @@ class TSINCRBY_Test extends PredisCommandTestCase $redis = $this->getClient(); $arguments = (new CreateArguments()) - ->retention(60000) + ->retentionMsecs(60000) ->duplicatePolicy(CommonArguments::POLICY_MAX) ->labels('sensor_id', 2, 'area_id', 32); @@ -125,7 +125,7 @@ class TSINCRBY_Test extends PredisCommandTestCase $redis = $this->getClient(); $arguments = (new CreateArguments()) - ->retention(60000) + ->retentionMsecs(60000) ->duplicatePolicy(CommonArguments::POLICY_MAX) ->labels('sensor_id', 2, 'area_id', 32); @@ -135,7 +135,7 @@ class TSINCRBY_Test extends PredisCommandTestCase ); $addArguments = (new AddArguments()) - ->retention(31536000000); + ->retentionMsecs(31536000000); $this->assertEquals( 123123123123, @@ -160,7 +160,7 @@ class TSINCRBY_Test extends PredisCommandTestCase ['key', 1.0, 'TIMESTAMP', 10], ], 'with RETENTION modifier' => [ - ['key', 1.0, (new IncrByArguments())->retention(100)], + ['key', 1.0, (new IncrByArguments())->retentionMsecs(100)], ['key', 1.0, 'RETENTION', 100], ], 'with UNCOMPRESSED modifier' => [ @@ -176,7 +176,7 @@ class TSINCRBY_Test extends PredisCommandTestCase ['key', 1.0, 'LABELS', 'label1', 1, 'label2', 2], ], 'with all modifiers' => [ - ['key', 1.0, (new IncrByArguments())->timestamp(10)->retention(100)->uncompressed()->chunkSize(100)->labels('label1', 1, 'label2', 2)], + ['key', 1.0, (new IncrByArguments())->timestamp(10)->retentionMsecs(100)->uncompressed()->chunkSize(100)->labels('label1', 1, 'label2', 2)], ['key', 1.0, 'TIMESTAMP', 10, 'RETENTION', 100, 'UNCOMPRESSED', 'CHUNK_SIZE', 100, 'LABELS', 'label1', 1, 'label2', 2], ], ]; diff --git a/tests/Predis/Command/Redis/TimeSeries/TSINFO_Test.php b/tests/Predis/Command/Redis/TimeSeries/TSINFO_Test.php new file mode 100644 index 00000000..1720cbc4 --- /dev/null +++ b/tests/Predis/Command/Redis/TimeSeries/TSINFO_Test.php @@ -0,0 +1,96 @@ +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 + * @requiresRedisTimeSeriesVersion >= 1.0.0 + */ + public function testReturnsInformationAboutGivenTimeSeries(): void + { + $redis = $this->getClient(); + $expectedResponse = ['totalSamples', 0, 'memoryUsage', 4239, 'firstTimestamp', 0, 'lastTimestamp', 0, + 'retentionTime', 60000, 'chunkCount', 1, 'chunkSize', 4096, 'chunkType', 'compressed', 'duplicatePolicy', + 'max', 'labels', [['sensor_id', '2'], ['area_id', '32']], 'sourceKey', null, 'rules', []]; + + $arguments = (new CreateArguments()) + ->retentionMsecs(60000) + ->duplicatePolicy(CommonArguments::POLICY_MAX) + ->labels('sensor_id', 2, 'area_id', 32); + + $this->assertEquals( + 'OK', + $redis->tscreate('temperature:2:32', $arguments) + ); + + $this->assertEquals($expectedResponse, $redis->tsinfo('temperature:2:32')); + } + + public function argumentsProvider(): array + { + return [ + 'with default arguments' => [ + ['key'], + ['key'], + ], + 'with DEBUG modifier' => [ + ['key', (new InfoArguments())->debug()], + ['key', 'DEBUG'], + ], + ]; + } +} diff --git a/tests/Predis/Command/Redis/TimeSeries/TSMADD_Test.php b/tests/Predis/Command/Redis/TimeSeries/TSMADD_Test.php index a4d4d986..649139b5 100644 --- a/tests/Predis/Command/Redis/TimeSeries/TSMADD_Test.php +++ b/tests/Predis/Command/Redis/TimeSeries/TSMADD_Test.php @@ -67,7 +67,7 @@ class TSMADD_Test extends PredisCommandTestCase $redis = $this->getClient(); $createArguments = (new CreateArguments()) - ->retention(60000) + ->retentionMsecs(60000) ->duplicatePolicy(CommonArguments::POLICY_MAX) ->labels('sensor_id', 2, 'area_id', 32); diff --git a/tests/Predis/Command/Redis/TimeSeries/TSMGET_Test.php b/tests/Predis/Command/Redis/TimeSeries/TSMGET_Test.php index a1986344..6b7acc47 100644 --- a/tests/Predis/Command/Redis/TimeSeries/TSMGET_Test.php +++ b/tests/Predis/Command/Redis/TimeSeries/TSMGET_Test.php @@ -69,7 +69,7 @@ class TSMGET_Test extends PredisCommandTestCase ]; $createArguments = (new CreateArguments()) - ->retention(60000) + ->retentionMsecs(60000) ->duplicatePolicy(CommonArguments::POLICY_MAX) ->labels('type', 'temp', 'sensor_id', 2, 'area_id', 32);