From e148178c314dab0c9cc198bf26c7917b2afe74af Mon Sep 17 00:00:00 2001 From: glaszig Date: Fri, 23 Jun 2023 17:33:31 -0300 Subject: [PATCH 1/4] fix TS.INFO parsing eliminate dependence on fixed positions of info properties --- src/TimeSeries.php | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/TimeSeries.php b/src/TimeSeries.php index 37d5404..bf0b51e 100644 --- a/src/TimeSeries.php +++ b/src/TimeSeries.php @@ -491,20 +491,40 @@ public function getLastSamples(Filter $filter): array public function info(string $key): Metadata { $result = $this->redis->executeCommand(['TS.INFO', $key]); + $result = $this->parseInfo($result); $labels = []; - foreach ($result[9] as $strLabel) { - $labels[] = new Label($strLabel[0], $strLabel[1]); + foreach ($result['labels'] as $label) { + $labels[] = new Label($label[0], $label[1]); } - $sourceKey = $result[11] === false ? null : $result[11]; + $sourceKey = $result['sourceKey'] === false ? null : $result['sourceKey']; $rules = []; - foreach ($result[13] as $rule) { + foreach ($result['rules'] as $rule) { $rules[$rule[0]] = new AggregationRule($rule[2], $rule[1]); } - return Metadata::fromRedis($result[1], $result[3], $result[5], $result[7], $labels, $sourceKey, $rules); + return Metadata::fromRedis( + $result['lastTimestamp'], + $result['retentionTime'], + $result['chunkCount'], + $result['maxSamplesPerChunk'], + $labels, + $sourceKey, + $rules + ); + } + + protected function parseInfo(array $info) + { + $chunks = array_chunk($result, 2); + $props = []; + foreach ($chunks as $chunk) { + $props[$chunk[0]] = $chunk[1]; + } + + return $props; } /** From ef8e943452e4f7008390d06a39f9b266814008d1 Mon Sep 17 00:00:00 2001 From: glaszig Date: Sat, 24 Jun 2023 22:19:15 -0300 Subject: [PATCH 2/4] fix variable name --- src/TimeSeries.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TimeSeries.php b/src/TimeSeries.php index bf0b51e..da9b59a 100644 --- a/src/TimeSeries.php +++ b/src/TimeSeries.php @@ -518,7 +518,7 @@ public function info(string $key): Metadata protected function parseInfo(array $info) { - $chunks = array_chunk($result, 2); + $chunks = array_chunk($info, 2); $props = []; foreach ($chunks as $chunk) { $props[$chunk[0]] = $chunk[1]; From a9d84956bf46b7649d37eeaf9a506dbf6118c346 Mon Sep 17 00:00:00 2001 From: glaszig Date: Sat, 24 Jun 2023 22:20:45 -0300 Subject: [PATCH 3/4] info(): prefer chunkSize over maxSamplesPerChunk see RedisTimeSeries/RedisTimeSeries#502 --- src/TimeSeries.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/TimeSeries.php b/src/TimeSeries.php index da9b59a..a8e8c82 100644 --- a/src/TimeSeries.php +++ b/src/TimeSeries.php @@ -509,7 +509,7 @@ public function info(string $key): Metadata $result['lastTimestamp'], $result['retentionTime'], $result['chunkCount'], - $result['maxSamplesPerChunk'], + $result['chunkSize'], $labels, $sourceKey, $rules @@ -524,6 +524,13 @@ protected function parseInfo(array $info) $props[$chunk[0]] = $chunk[1]; } + // maxSamplesPerChunk has been replaced with chunkSize in 1.4.4 + // https://github.com/RedisTimeSeries/RedisTimeSeries/commit/5896a509e5ec30929c04cd96a7f8b2c9e9651ed9 + $props['chunkSize'] = isset($props['chunkSize']) + ? $props['chunkSize'] + : $props['maxSamplesPerChunk'] + ; + return $props; } From ce1a7b738cfa413e9c75988f3154c584e36bc4f2 Mon Sep 17 00:00:00 2001 From: glaszig Date: Mon, 26 Jun 2023 20:32:44 -0300 Subject: [PATCH 4/4] add return type to TimeSeries::parseInfo() --- src/TimeSeries.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TimeSeries.php b/src/TimeSeries.php index a8e8c82..a963d11 100644 --- a/src/TimeSeries.php +++ b/src/TimeSeries.php @@ -516,7 +516,7 @@ public function info(string $key): Metadata ); } - protected function parseInfo(array $info) + protected function parseInfo(array $info): array { $chunks = array_chunk($info, 2); $props = [];