Closed hulimatata closed 3 years ago
@hulimatata since RedisTimeSeries 1.4 we've added the ability to back-fill time series, with different duplicate policies.
The following are the possible policies:
SUM - If a previous sample exists, add the new sample to it so that the updated value is equal to (previous + new). If no previous sample exists, set the updated value equal to the new value.
The default behavior is to block updates to the same timestamp.
You can check our docs more in deep section about duplicate policy here: https://oss.redislabs.com/redistimeseries/configuration/#duplicate_policy.
Let's check with two python examples:
default: BLOCK - an error will occur for any out of order sample
from redistimeseries.client import Client
rts = Client()
rts.create('block-upsert', labels={'Time':'Series'})
rts.add('block-upsert', 1, 10.0)
rts.add('block-upsert', 1, 5.0)
This block of code should output the following exception:
redis.exceptions.ResponseError: TSDB: Error at upsert, update is not supported in BLOCK mode
LAST - override with latest value
from redistimeseries.client import Client
rts = Client()
rts.create('last-upsert', labels={'Time':'Series'},duplicate_policy='last')
rts.add('last-upsert', 1, 10.0)
rts.add('last-upsert', 1, 5.0)
# should output [(1, 5.0)]
print(rts.range('last-upsert', 0, -1))
This block of code should output the following exception:
[(1, 5.0)]
@hulimatata I believe we should add further notes about duplicate policy to the Readme ( this is recurrent question ). Will open a PR about it @gkorland
redis.exceptions.ResponseError: TSDB: Error at upsert, update is not supported in BLOCK mode
How to solve this problem