Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Doubts on duplicate policy #86

Closed
hulimatata opened this issue Apr 27, 2021 · 1 comment · Fixed by #87
Closed

Doubts on duplicate policy #86

hulimatata opened this issue Apr 27, 2021 · 1 comment · Fixed by #87
Assignees
Labels
question Further information is requested

Comments

@hulimatata
Copy link

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

How to solve this problem

@filipecosta90 filipecosta90 added the question Further information is requested label Apr 27, 2021
@filipecosta90 filipecosta90 changed the title BUG Doubts on duplicate policy Apr 27, 2021
@filipecosta90
Copy link
Collaborator

@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:

  • BLOCK - an error will occur for any out of order sample
  • FIRST - ignore the new value
  • LAST - override with latest value
  • MIN - only override if the value is lower than the existing value
  • MAX - only override if the value is higher than the existing value
  • 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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants