RedisTimeSeries / redistimeseries-py

RedisTimeSeries python client
https://redistimeseries.io
BSD 3-Clause "New" or "Revised" License
99 stars 21 forks source link

Pipelining get #78

Open elan-izidane opened 4 years ago

elan-izidane commented 4 years ago

Hi, I am trying to run something like:

pipeline = time_series_client.pipeline(transaction=False)
for key in my_list_of_keys:
    pipeline.get(key)
my_data = pipeline.execute()

This does not work, I could not find tests for get with pipelines. Adding works great though. My guess is that it is doing a "GET" and not a "TS.GET" (have not tested this).

gkorland commented 4 years ago
from redistimeseries.client import Client
rts = Client()
rts.create('test', labels={'Time':'Series'})
rts.add('test', 1, 1.12)
rts.add('test', 2, 1.12)

pipeline = rts.pipeline(transaction=False)
pipeline.get('test')
print(pipeline.execute() )

result [(2, 1.12)]

ilieszidane commented 3 years ago

Hi, Thanks vm for your response.

Here is my code:

from redistimeseries.client import Client as RedisTS
client_kwargs = {"host": hostname, "port": port, "decode_responses": True}
rts = RedisTS(**client_kwargs)
rts.create('test', labels={'Time': 'Series'})
rts.add('test', 1, 1.12)
rts.add('test', 2, 1.12)

print(rts.get('test'))

pipeline = rts.pipeline(transaction=False)
pipeline.get('test')
print(pipeline.execute())

The first print does print (2, 1.12), the second raises:

Exception has occurred: ResponseError
Command # 1 (GET test) of pipeline caused error: WRONGTYPE Operation against a key holding the wrong kind of value
  File "/usr/local/pip-global/redis/connection.py", line 756, in read_response
    raise response
  File "/usr/local/pip-global/redis/client.py", line 915, in parse_response
    response = connection.read_response()
  File "/usr/local/pip-global/redis/client.py", line 3977, in parse_response
    result = Redis.parse_response(
  File "/usr/local/pip-global/redis/client.py", line 3961, in _execute_pipeline
    self.raise_first_error(commands, response)
  File "/usr/local/pip-global/redis/client.py", line 3968, in raise_first_error
    raise r
  File "/usr/local/pip-global/redis/client.py", line 3961, in _execute_pipeline
    self.raise_first_error(commands, response)
  File "/usr/local/pip-global/redis/client.py", line 4019, in execute
    return execute(conn, stack, raise_on_error)
  File "/workspaces/app/command/play_with_redis.py", line 31, in <module>
    print(pipeline.execute())

I am running redislabs/redismod:latest and this client.

$ pip3 freeze | grep redis
hiredis==1.1.0
redis==3.5.3
redistimeseries==1.4.3

output of module list on the cli:

>> module list

1) 1) "name"
   2) "bf"
   3) "ver"
   4) (integer) 20204
2) 1) "name"
   2) "search"
   3) "ver"
   4) (integer) 20003
3) 1) "name"
   2) "ai"
   3) "ver"
   4) (integer) 10002
4) 1) "name"
   2) "timeseries"
   3) "ver"
   4) (integer) 10406
5) 1) "name"
   2) "rg"
   3) "ver"
   4) (integer) 10003
6) 1) "name"
   2) "graph"
   3) "ver"
   4) (integer) 20208
7) 1) "name"
   2) "ReJSON"
   3) "ver"
   4) (integer) 10006

Thanks vm for your help!