Reputation: 199
I am trying to use the Python redistimeseries package (RedisLabs v0.8.0) Python Redis package (RedisLabs) v3.5.3
However when I perform a TS.ADD - it always returns the error
redis.exceptions.ResponseError: TSDB: Timestamp cannot be older than the latest timestamp in the time series
no matter what timestamp I give it. I can take the same timestamp value, and do the same ADD in redis-cli on the same time-series without any issue.
To make sure existing records are not the issue I create a new time-series, so no keys/values/timestamps exist. same result.
Example:
REDIS-CLI 127.0.0.1:6379> TS.CREATE FAN02.RUNTIME RETENTION 604800 LABELS eq_type FANS location SITE1
REDIS-CLI 127.0.0.1:6379> TS.ADD FAN04.RUNTIME 1591720015 39
(integer) 1591720015
works fine.
But if I do the same in Python (using a new empty time-series), using a current timestamp I get the error;
>>> int(time.time())
1591720015
import redistimeseries.client
rts = redistimeseries.client.Client(host='x.x.x.x', port=6379)
rts.add('FAN04.RUNTIME', int(time.time()), newval)
>>> stacktrace
File "C:/.../putdata.py", line 105, in main
rts.add('FAN04.RUNTIME', int(time.time()), newval)
File "C:\...\venv\lib\site-packages\redistimeseries\client.py", line 186, in add
return self.execute_command(self.ADD_CMD, *params)
File "C:\...\venv\lib\site-packages\redis\client.py", line 901, in execute_command
return self.parse_response(conn, command_name, **options)
File "C:\...\venv\lib\site-packages\redis\client.py", line 915, in parse_response
response = connection.read_response()
File "C:\...\venv\lib\site-packages\redis\connection.py", line 756, in read_response
raise response
redis.exceptions.ResponseError: TSDB: Timestamp cannot be older than the latest timestamp in the time series
Not sure what is going on or what I am doing incorrectly, I am having a hard time finding documentation or examples for the Python package that would highlight my error or lack of understanding.
Any ideas ?
I am using Python 3.7, Redis 3.5.3, Redis TimeSeries 0.8.0
Upvotes: 0
Views: 1893
Reputation: 49942
Python's time.time()
returns the current time as a floating point value of the seconds, whereas RedisTimeSeries expects millisecond resolution... Try:
rts.add('FAN04.RUNTIME', int(time.time() * 1000), newval)
Or use datetime
's now()
or similar...
Upvotes: 3