RedisTimeSeries / redistimeseries-py

RedisTimeSeries python client
https://redistimeseries.io
BSD 3-Clause "New" or "Revised" License
99 stars 21 forks source link

Doubts on duplicate policy #86

Closed hulimatata closed 3 years ago

hulimatata commented 3 years ago

redis.exceptions.ResponseError: TSDB: Error at upsert, update is not supported in BLOCK mode

How to solve this problem

filipecosta90 commented 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:

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