Skip to content

Commit

Permalink
fix TS.INFO parsing
Browse files Browse the repository at this point in the history
eliminate dependence on fixed positions of info properties
  • Loading branch information
glaszig committed Jun 23, 2023
1 parent 3b53ffa commit 60ed1a5
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/TimeSeries.php
Original file line number Diff line number Diff line change
Expand Up @@ -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->parseInfoResult($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 parseInfoResult(array $info)
{
$chunks = array_chunk($result, 2);
$props = [];
foreach ($chunks as $chunk) {
$props[$chunk[0]] = $chunk[1];
}

return $props;
}

/**
Expand Down

0 comments on commit 60ed1a5

Please sign in to comment.