0

我正在尝试使用 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 中执行相同的 ADD,而不会出现任何问题。

为了确保现有记录不是问题,我创建了一个新的时间序列,因此不存在键/值/时间戳。同样的结果。

例子:

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 包的文档或示例,这些文档或示例会突出我的错误或缺乏理解。

有任何想法吗 ?

我正在使用 Python 3.7、Redis 3.5.3、Redis TimeSeries 0.8.0

4

1 回答 1

3

Pythontime.time()将当前时间作为秒的浮点值返回,而 RedisTimeSeries 需要毫秒分辨率...尝试:

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

或使用datetime'snow()或类似...

于 2020-06-09T23:22:25.910 回答