redisredistimeseries

Redis Timeseries mget does not fetch labels


I am trying to add labeled data to a Redis timeseries. Using Python I add the data, but trying to fetch the data using mget does not get anything. All I get is an empty list:

import redis

rd = redis.StrictRedis(host='localhost', port=6379, decode_responses=True)
rd.flushall()

ts = rd.ts() # The timeseries object
ts.create("foo", retention_msecs=90*24*60*60*1000) # 90 days expiration
ts.add("foo", 1, 100, labels={"org": "Apple", "suborg": "Engineering"})
result = ts.mget([f"org=Apple"], with_labels=True)
print(result)

Results:

[]

I expected the results from the print to NOT be an empty list.

Is this a bug, or am I doing something wrong here?

For reference, some docs for redis timeseries for python: https://redis-py.readthedocs.io/en/stable/redismodules.html#redis.commands.json.commands.JSONCommands.mget

Also some general guides on how to use redis timeseries with python: https://redis-py.readthedocs.io/en/stable/examples/timeseries_examples.html


Solution

  • The creation parameters in ts.add and ts.madd are only being used if the key didn't existed before.

    Since "foo" already created by ts.create, the creation parameters are ignored.

    You can add the labels to the create command as follows: ts.create("foo", retention_msecs=902460601000, labels={"org": "Apple", "suborg": "Engineering"}) # 90 days expiration