skip to Main Content

i need help with redistimeseries python client. When i use redisclientobject.range() method of python client, i am unable to provide the optional field [Latest]. is it not supported by python library?.. using "Latest" is critical for me because, when i do aggregation, i need the ongoing bucket data (partial).
the same problem is observed with get, mget functions too.

Background. : i am storing live stock data (ticks) and i use compaction (aggregation) by creating rule. At the same time, i need to plot the live tick data on the chart which means i need the latest ongoing compaction data .
Whereas when i use redis cli and issue ts.range key – + latest , i get the ongoing compaction. But in Python client library i do not know if it is possible. I have checked the def range() method of the Client class and i believe that the optional field ‘Latest’ is not implemented

on the redis cli below are the results

TS.RANGE VWAP:ticks:MCX:CRUDEOIL22SEPFUT 1662717300000 1662791113000 latest

////

    1. (integer) 1662717300000
    2. 738244
    1. (integer) 1662717600000
    2. 724450

and without latest,

TS.RANGE VWAP:5min:MCX:CRUDEOIL22SEPFUT 1662717300000 1662791113000

    1. (integer) 1662717300000
    2. 738244

2

Answers


  1. Chosen as BEST ANSWER

    I have subclassed the client and modified the get method as follows (actually renamed get method to myget instead of overriding)

    class myRedisTSClient(Client): def init(self, conn=None, *args, **kwargs): super().init(conn, *args, **kwargs)

    def myget(self,key,latest=False) :
        """Gets the last sample of ``key``"""
        if latest :
            paramLatest = 'LATEST'
            logging.info(f"COMMAND TO BE SET : {self.GET_CMD} {key} {paramLatest}")
            return self.redis.execute_command(self.GET_CMD, key, paramLatest)
        else :
            return self.redis.execute_command(self.GET_CMD, key)
    

  2. Are you using the latest redis-py (4.4.0rc1)?

    https://github.com/redis/redis-py/pull/2296

    https://github.com/redis/redis-py/releases/tag/v4.4.0rc1

    Note that RedisTimeSeries 1.8 is still a release candidate.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search