def pack_command(self, *args): output = [] command = args[0] if ' ' in command: args = tuple([Token.get_token(s) for s in command.split()]) + args[1:] else: args = (Token.get_token(command), ) + args[1:] buff = SYM_EMPTY.join((SYM_STAR, b(str(len(args))), SYM_CRLF)) for arg in imap(self.encoder.encode, args): if len(buff) > 6000 or len(arg) > 6000: buff = SYM_EMPTY.join( (buff, SYM_DOLLAR, b(str(len(arg))), SYM_CRLF)) output.append(buff) output.append(arg) buff = SYM_CRLF else: buff = SYM_EMPTY.join((buff, SYM_DOLLAR, b(str(len(arg))), SYM_CRLF, arg, SYM_CRLF)) output.append(buff) return output
def tsrevrangebytime(self, name, tm_low=None, tm_high=None, num=None, time_cast_func=DatetimeToTimestamp(pytz.utc), timestamp_cast_func=TimestampToDatetime(pytz.utc)): """ Returns the entries for the given time range from ``tm_low`` to ``tm_high`` in the time series that is specified by the given key ``name``. The entries are returned in descending order of the times. Special bounds -inf (``tm_low`` is None or -inf) and +inf (``tm_high`` is None or inf) are also supported to retrieve an entire range. If ``num`` is specified, then at most ``num`` entries will be fetched. ``time_cast_func`` a callable used to cast the time ``tm`` to a timestamp - 64 bit signed integer (cf. ``tsadd``). ``timestamp_cast_func`` a callable used to cast the timestamp return values. It should reflect how timestamp were inserted (cf. ``time_cast_func``). """ pieces = ['TSREVRANGEBYTIME', name] if tm_low is None or (isinstance(tm_low, float) and isinf(tm_low)): pieces.append(m_inf) elif time_cast_func is None: pieces.append(tm_low) else: pieces.append(time_cast_func(tm_low)) if tm_high is None or (isinstance(tm_high, float) and isinf(tm_high)): pieces.append(p_inf) elif time_cast_func is None: pieces.append(tm_high) else: pieces.append(time_cast_func(tm_high)) if num is not None: pieces.extend([Token.get_token('LIMIT'), num]) if timestamp_cast_func is None: return self.execute_command(*pieces, timestamp_cast_func=int) return self.execute_command(*pieces, timestamp_cast_func=timestamp_cast_func)