phpRedisTimeSeries icon indicating copy to clipboard operation
phpRedisTimeSeries copied to clipboard

Error when getting Range for non-existent key - foreach() argument must be of type array|object, bool given

Open texnicii opened this issue 1 year ago • 0 comments

RedisClient::executeCommand() uses Redis::rawCommand() and Redis::rawCommand() may return false. Therefore $rawResults may contains false and it will throws the error when false put to foreach

https://github.com/palicao/phpRedisTimeSeries/blob/3b53ffa5e23e7032e2c68a1795100fa4906ce5fa/src/TimeSeries.php#L322

$rawResults = $this->redis->executeCommand(array_merge($params, $this->getAggregationParams($rule)));

$samples = [];
foreach ($rawResults as $rawResult) {
    $samples[] = Sample::createFromTimestamp($key, (float)$rawResult[1], (int)$rawResult[0]);
}

texnicii avatar Jun 21 '23 07:06 texnicii