python redistimeries时间戳不能早于时间序列中的最新时间戳

hl0ma9xz  于 2021-06-09  发布在  Redis
关注(0)|答案(1)|浏览(451)

我正在尝试使用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、redis3.5.3、redistimeseries0.8.0

pokxtpni

pokxtpni1#

Python的 time.time() 以秒的浮点值返回当前时间,而redistimeseries要求毫秒分辨率。。。尝试:

rts.add('FAN04.RUNTIME', int(time.time() * 1000), newval)

或使用 datetimenow() 或者类似的。。。

相关问题