我正在尝试使用Python redistimeseries包(RedisLabs v0.8.0) Python Redis包(RedisLabs) v3.5.3
但是,当我执行TS.ADD时-它总是返回错误
redis.exceptions.ResponseError: TSDB: Timestamp cannot be older than the latest timestamp in the time series不管我给它加什么时间戳。我可以获取相同的时间戳值,并在相同的时间序列上执行相同的redis-cli添加操作,而不会出现任何问题。
为了确保现有记录不是问题所在,我创建了一个新的时间序列,因此不存在键/值/时间戳。同样的结果。
示例:
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工作正常。
但是如果我在Python中做同样的事情(使用一个新的空时间序列),使用当前时间戳,我会得到错误;
>>> 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不确定发生了什么或者我做错了什么,我很难找到Python包的文档或示例来突出我的错误或缺乏理解。
有什么想法吗?
我使用的是python3.7,Redis 3.5.3,Redis TimeSeries 0.8.0
发布于 2020-06-10 07:22:26
Python的time.time()以秒的浮点值的形式返回当前时间,而RedisTimeSeries期望毫秒级的精度...尝试:
rts.add('FAN04.RUNTIME', int(time.time() * 1000), newval)或者使用datetime的now()或类似的。
https://stackoverflow.com/questions/62287577
复制相似问题