This repository was archived by the owner on Jan 24, 2023. It is now read-only.
This repository was archived by the owner on Jan 24, 2023. It is now read-only.
List index out of range in parse_m_get() for emty series. #49
Closed
Description
I use Redis v5.0.5 + RedisTimeSeries module v.1.2.2
Now TS.MGET return array will contain key1, labels1, lastsample1, ..., keyN, labelsN, lastsampleN if series contain some data point. But if series is empty, then TS.MGET in my case return:
1) "analog-key1"
2) 1) 1) "type"
2) "analog"
3) (empty list or set)
The function parse_m_get()
can fail as soon as it encounters an empty series.
Because item [2] [0]
and item [2] [1]
will refer to an empty list and will throw an exception "list index out of range".
In version 1.0GA, the RedistimeSeries module when executing TS.MGET would return for an empty series:
- "analog-key1"
2) 1) 1) "type"
2) "analog"
3) (integer) 0
4) "0"
For my project, I changed the behavior of the parse_m_get
function to maintain compatibility with existing code:
def parse_m_get(response):
res = []
for item in response:
print(item)
res.append(
{
nativestr(item[0]) : [list_to_dict(item[1]),
item[2][0] if item[2] else 0,
float(item[2][1]) if item[2] else '0']
}
)
return res
I can make a pull request if this solution is correct.