o
    LjIT                    @   s   d dl mZmZmZmZmZmZmZ d dlm	Z	 d dl
mZmZmZmZmZmZmZmZmZ ddlmZ dZdZdZd	Zd
ZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*G dd dZ+dS )    )Any	AwaitableDictIterableListTupleoverload)	DataError)	AsyncClientProtocol
EncodableTKeyTNumberSyncClientProtocolTimeSeriesMRangeResponseTimeSeriesNRangeResponseTimeSeriesRangeResponseTimeSeriesSample   )TSInfozTS.ADDzTS.ALTERzTS.CREATERULEz	TS.CREATEz	TS.DECRBYzTS.DELETERULEzTS.DELzTS.GETz	TS.INCRBYzTS.INFOzTS.MADDzTS.MGETz	TS.MRANGEzTS.MREVRANGEz	TS.NRANGEzTS.NREVRANGEzTS.QUERYINDEXzTS.QUERYLABELSzTS.RANGEzTS.READzTS.REVRANGEc                +   @   s  e Zd ZdZe							ddedededB dedB de	e
e
f dB d	edB d
e
dB dedB dedB defddZe							ddedededB dedB de	e
e
f dB d	edB d
e
dB dedB dedB dee fddZ							ddededB dedB de	e
e
f dB d	edB d
e
dB dedB dedB deee B fddZe						ddedededB de	e
e
f dB d	edB d
e
dB dedB dedB defddZe						ddedededB de	e
e
f dB d	edB d
e
dB dedB dedB dee fddZ						ddededB de	e
e
f dB d	edB d
e
dB dedB dedB deee B fddZe								ddededee
B dee
B dedB dedB de	e
e
f dB d	edB d
e
dB dedB dedB de
dB defddZe								ddededee
B dee
B dedB dedB de	e
e
f dB d	edB d
e
dB dedB dedB de
dB dee fddZ								ddedee
B dee
B dedB dedB de	e
e
f dB d	edB d
e
dB dedB dedB de
dB deee B fddZededeeeee
B ee
B f  dee fddZededeeeee
B ee
B f  deee  fd dZdeeeee
B ee
B f  dee eee  B fd!dZe								ddedededee
B dB dedB dedB de	e
e
f dB d	edB d
e
dB dedB dedB defd"d#Ze								ddedededee
B dB dedB dedB de	e
e
f dB d	edB d
e
dB dedB dedB dee fd$d#Z								ddededee
B dB dedB dedB de	e
e
f dB d	edB d
e
dB dedB dedB deee B fd%d#Ze								ddedededee
B dB dedB dedB de	e
e
f dB d	edB d
e
dB dedB dedB defd&d'Ze								ddedededee
B dB dedB dedB de	e
e
f dB d	edB d
e
dB dedB dedB dee fd(d'Z								ddededee
B dB dedB dedB de	e
e
f dB d	edB d
e
dB dedB dedB deee B fd)d'Zededed*ed+edef
d,d-Zededed*ed+edee f
d.d-Zded*ed+edeee B fd/d-Ze	dded0ed1ed2e
d3ed4edB defd5d6Ze	dded0ed1ed2e
d3ed4edB dee fd7d6Z	dd0ed1ed2e
d3ed4edB deee B fd8d6Zeded0ed1edefd9d:Zeded0ed1edee fd;d:Zd0ed1edeee B fd<d:Zded*ee
B d+ee
B d=edB d2e
ee
 B dB d3edB d>ee dB d?edB d@edB dAee
B dB dBedB dCe
dB dDedB fdEdFZe			G							ddeded*ee
B d+ee
B d=edB d2e
ee
 B dB d3edB d>ee dB d?edB d@edB dAee
B dB dBedB dCe
dB dDedB defdHdIZe			G							ddeded*ee
B d+ee
B d=edB d2e
ee
 B dB d3edB d>ee dB d?edB d@edB dAee
B dB dBedB dCe
dB dDedB dee fdJdIZ			G							dded*ee
B d+ee
B d=edB d2e
ee
 B dB d3edB d>ee dB d?edB d@edB dAee
B dB dBedB dCe
dB dDedB deee B fdKdIZe			G							ddeded*ee
B d+ee
B d=edB d2e
ee
 B dB d3edB d>ee dB d?edB d@edB dAee
B dB dBedB dCe
dB dDedB defdLdMZe			G							ddeded*ee
B d+ee
B d=edB d2e
ee
 B dB d3edB d>ee dB d?edB d@edB dAee
B dB dBedB dCe
dB dDedB dee fdNdMZ			G							dded*ee
B d+ee
B d=edB d2e
ee
 B dB d3edB d>ee dB d?edB d@edB dAee
B dB dBedB dCe
dB dDedB deee B fdOdMZe			ddededee
B dPedB dQedB dRedB defdSdTZe			ddededee
B dPedB dQedB dRedB dee fdUdTZ			ddedee
B dPedB dQedB dRedB deee B fdVdTZdWee d*ee
B d+ee
B d=edB dXe
ee
 B dB d3edB d>ee dB d?edB d@edB dAee
B dB dBedB dCe
dB dDedB fdYdZZe			G							ddedWee d*ee
B d+ee
B d=edB dXe
ee
 B dB d3edB d>ee dB d?edB d@edB dAee
B dB dBedB dCe
dB dDedB de fd[d\Z!e			G							ddedWee d*ee
B d+ee
B d=edB dXe
ee
 B dB d3edB d>ee dB d?edB d@edB dAee
B dB dBedB dCe
dB dDedB dee  fd]d\Z!			G							ddWee d*ee
B d+ee
B d=edB dXe
ee
 B dB d3edB d>ee dB d?edB d@edB dAee
B dB dBedB dCe
dB dDedB de ee  B fd^d\Z!e			G							ddedWee d*ee
B d+ee
B d=edB dXe
ee
 B dB d3edB d>ee dB d?edB d@edB dAee
B dB dBedB dCe
dB dDedB de fd_d`Z"e			G							ddedWee d*ee
B d+ee
B d=edB dXe
ee
 B dB d3edB d>ee dB d?edB d@edB dAee
B dB dBedB dCe
dB dDedB dee  fdad`Z"			G							ddWee d*ee
B d+ee
B d=edB dXe
ee
 B dB d3edB d>ee dB d?edB d@edB dAee
B dB dBedB dCe
dB dDedB de ee  B fdbd`Z"d2e
ee
 B dB d3edB d=edB dcee
 d*ee
B d+ee
B ddedB d>ee dB d?edB d@edB dee
dB dfe
dB dgee
 dB dAee
B dB dBedB dCe
dB dDedB dhedB f$didjZ#e			G												dded*ee
B d+ee
B dcee
 d=edB d2e
ee
 B dB d3edB ddedB d>ee dB d?edB d@edB dee
dB dfe
dB dgee
 dB dAee
B dB dBedB dCe
dB dDedB dhedB de$f(dkdlZ%e			G												dded*ee
B d+ee
B dcee
 d=edB d2e
ee
 B dB d3edB ddedB d>ee dB d?edB d@edB dee
dB dfe
dB dgee
 dB dAee
B dB dBedB dCe
dB dDedB dhedB dee$ f(dmdlZ%			G												dd*ee
B d+ee
B dcee
 d=edB d2e
ee
 B dB d3edB ddedB d>ee dB d?edB d@edB dee
dB dfe
dB dgee
 dB dAee
B dB dBedB dCe
dB dDedB dhedB de$ee$ B f&dndlZ%e			G												dded*ee
B d+ee
B dcee
 d=edB d2e
ee
 B dB d3edB ddedB d>ee dB d?edB d@edB dee
dB dfe
dB dgee
 dB dAee
B dB dBedB dCe
dB dDedB dhedB de$f(dodpZ&e			G												dded*ee
B d+ee
B dcee
 d=edB d2e
ee
 B dB d3edB ddedB d>ee dB d?edB d@edB dee
dB dfe
dB dgee
 dB dAee
B dB dBedB dCe
dB dDedB dhedB dee$ f(dqdpZ&			G												dd*ee
B d+ee
B dcee
 d=edB d2e
ee
 B dB d3edB ddedB d>ee dB d?edB d@edB dee
dB dfe
dB dgee
 dB dAee
B dB dBedB dCe
dB dDedB dhedB de$ee$ B f&drdpZ&e	ddededBedB de'dB fdsdtZ(e	ddededBedB dee'dB  fdudtZ(ddedBedB de'dB ee'dB  B fdvdtZ(e			ddedcee
 ddedB dgee
 dB dBedB dee) e*e
ee) f B fdwdxZ+e			ddedcee
 ddedB dgee
 dB dBedB deee) e*e
ee) f B  fdydxZ+			ddcee
 ddedB dgee
 dB dBedB dee) e*e
ee) f B eee) e*e
ee) f B  B f
dzdxZ+ededede,e*e
e)f B fd{d|Z-edededee,e*e
e)f B  fd}d|Z-dede,e*e
e)f B ee,e*e
e)f B  B fd~d|Z-ededcee
 dee.e
B  fddZ/ededcee
 deee.e
B   fddZ/dcee
 dee.e
B  eee.e
B   B fddZ/e		ddede
dB dce0e
 dB de1e.e
B  fddZ2e		ddede
dB dce0e
 dB dee1e.e
B   fddZ2	dde
dB dce0e
 dB de1e.e
B  ee1e.e
B   B fddZ2e3dee4 dce0e
 dB fddZ5e3dee4 dedB fddZ6e3dee4 ddedB dgee
 dB fddZ7e3dee4 dee
dB dfe
dB fddZ8e3dee4 dedB fddZ9e3dee4 de*e
e
f dB fddZ:e3dee4 d=edB fddZ;e3dee4 dPedB dQedB fddZ<e3dee4 dRedB fddZ=e3dee4 dedB fddZ>e3dee4 dAee
B dB fddZ?e3dee4 d2e
ee
 B dB d3edB fddZ@e3dee4 dXe
ee
 B dB d3edB defddZAe3dee4 d	edB fddZBe3dee4 d
e
dB fddZCe3dee4 de
dB fddZDe3dee4 dee dB fddZEe3dee4 dedB dedB fddZFe3dee4 dBedB fddZGe3dee4 dCe
dB fddZHe3dee4 dDedB fddZIe3dee4 dhedB fddZJe3		ddee4 dedB dedB fddZKdS )TimeSeriesCommandszRedisTimeSeries Commands.NFselfkeyretention_msecsuncompressedlabels
chunk_sizeduplicate_policyignore_max_time_diffignore_max_val_diffreturnc	           	      C      d S N 	r   r   r   r   r   r   r   r   r   r"   r"   `/home/djax/ivt_ai_plugin/venv/lib/python3.10/site-packages/redis/commands/timeseries/commands.pycreate,      zTimeSeriesCommands.createc	           	      C   r    r!   r"   r#   r"   r"   r$   r%   9   r&   c	           
      C   sb   |g}	|  |	| | |	| | |	| | |	| | |	| | |	|| | jtg|	R  S )a9
  
        Create a new time-series.

        For more information see https://redis.io/commands/ts.create/

        Args:
            key:
                The time-series key.
            retention_msecs:
                Maximum age for samples, compared to the highest reported timestamp in
                milliseconds. If `None` or `0` is passed, the series is not trimmed at
                all.
            uncompressed:
                Changes data storage from compressed (default) to uncompressed.
            labels:
                A dictionary of label-value pairs that represent metadata labels of the
                key.
            chunk_size:
                Memory size, in bytes, allocated for each data chunk. Must be a multiple
                of 8 in the range `[48..1048576]`. In earlier versions of the module the
                minimum value was different.
            duplicate_policy:
                Policy for handling multiple samples with identical timestamps. Can be
                one of:

                - 'block': An error will occur and the new value will be ignored.
                - 'first': Ignore the new value.
                - 'last': Override with the latest value.
                - 'min': Only override if the value is lower than the existing value.
                - 'max': Only override if the value is higher than the existing value.
                - 'sum': If a previous sample exists, add the new sample to it so
                  that the updated value is equal to (previous + new). If no
                  previous sample exists, set the updated value equal to the new
                  value.

            ignore_max_time_diff:
                A non-negative integer value, in milliseconds, that sets an ignore
                threshold for added timestamps. If the difference between the last
                timestamp and the new timestamp is lower than this threshold, the new
                entry is ignored. Only applicable if `duplicate_policy` is set to
                `last`, and if `ignore_max_val_diff` is also set. Available since
                RedisTimeSeries version 1.12.0.
            ignore_max_val_diff:
                A non-negative floating point value, that sets an ignore threshold for
                added values. If the difference between the last value and the new value
                is lower than this threshold, the new entry is ignored. Only applicable
                if `duplicate_policy` is set to `last`, and if `ignore_max_time_diff` is
                also set. Available since RedisTimeSeries version 1.12.0.
        )_append_retention_append_uncompressed_append_chunk_size_append_duplicate_policy_append_labels_append_insertion_filtersexecute_command
CREATE_CMD)
r   r   r   r   r   r   r   r   r   paramsr"   r"   r$   r%   F   s   <c                 C   r    r!   r"   r   r   r   r   r   r   r   r   r"   r"   r$   alter      
zTimeSeriesCommands.alterc                 C   r    r!   r"   r0   r"   r"   r$   r1      r2   c           	      C   sV   |g}|  || | || | || | || | ||| | jtg|R  S )a
  
        Update an existing time series.

        For more information see https://redis.io/commands/ts.alter/

        Args:
            key:
                The time-series key.
            retention_msecs:
                Maximum age for samples, compared to the highest reported timestamp in
                milliseconds. If `None` or `0` is passed, the series is not trimmed at
                all.
            labels:
                A dictionary of label-value pairs that represent metadata labels of the
                key.
            chunk_size:
                Memory size, in bytes, allocated for each data chunk. Must be a multiple
                of 8 in the range `[48..1048576]`. In earlier versions of the module the
                minimum value was different. Changing this value does not affect
                existing chunks.
            duplicate_policy:
                Policy for handling multiple samples with identical timestamps. Can be
                one of:

                - 'block': An error will occur and the new value will be ignored.
                - 'first': Ignore the new value.
                - 'last': Override with the latest value.
                - 'min': Only override if the value is lower than the existing value.
                - 'max': Only override if the value is higher than the existing value.
                - 'sum': If a previous sample exists, add the new sample to it so
                  that the updated value is equal to (previous + new). If no
                  previous sample exists, set the updated value equal to the new
                  value.

            ignore_max_time_diff:
                A non-negative integer value, in milliseconds, that sets an ignore
                threshold for added timestamps. If the difference between the last
                timestamp and the new timestamp is lower than this threshold, the new
                entry is ignored. Only applicable if `duplicate_policy` is set to
                `last`, and if `ignore_max_val_diff` is also set. Available since
                RedisTimeSeries version 1.12.0.
            ignore_max_val_diff:
                A non-negative floating point value, that sets an ignore threshold for
                added values. If the difference between the last value and the new value
                is lower than this threshold, the new entry is ignored. Only applicable
                if `duplicate_policy` is set to `last`, and if `ignore_max_time_diff` is
                also set. Available since RedisTimeSeries version 1.12.0.
        )r'   r)   r*   r+   r,   r-   	ALTER_CMD)	r   r   r   r   r   r   r   r   r/   r"   r"   r$   r1      s   :	timestampvalueon_duplicatec                 C   r    r!   r"   r   r   r4   r5   r   r   r   r   r   r   r   r6   r"   r"   r$   add      zTimeSeriesCommands.addc                 C   r    r!   r"   r7   r"   r"   r$   r8      r9   c                 C   sr   |||g}|  || | || | || | || | || | ||	|
 | || | jtg|R  S )a  
        Append a sample to a time series. When the specified key does not exist, a new
        time series is created.

        For more information see https://redis.io/commands/ts.add/

        Args:
            key:
                The time-series key.
            timestamp:
                Timestamp of the sample. `*` can be used for automatic timestamp (using
                the system clock).
            value:
                Numeric data value of the sample.
            retention_msecs:
                Maximum age for samples, compared to the highest reported timestamp in
                milliseconds. If `None` or `0` is passed, the series is not trimmed at
                all.
            uncompressed:
                Changes data storage from compressed (default) to uncompressed.
            labels:
                A dictionary of label-value pairs that represent metadata labels of the
                key.
            chunk_size:
                Memory size, in bytes, allocated for each data chunk. Must be a multiple
                of 8 in the range `[48..1048576]`. In earlier versions of the module the
                minimum value was different.
            duplicate_policy:
                Policy for handling multiple samples with identical timestamps. Can be
                one of:

                - 'block': An error will occur and the new value will be ignored.
                - 'first': Ignore the new value.
                - 'last': Override with the latest value.
                - 'min': Only override if the value is lower than the existing value.
                - 'max': Only override if the value is higher than the existing value.
                - 'sum': If a previous sample exists, add the new sample to it so
                  that the updated value is equal to (previous + new). If no
                  previous sample exists, set the updated value equal to the new
                  value.

            ignore_max_time_diff:
                A non-negative integer value, in milliseconds, that sets an ignore
                threshold for added timestamps. If the difference between the last
                timestamp and the new timestamp is lower than this threshold, the new
                entry is ignored. Only applicable if `duplicate_policy` is set to
                `last`, and if `ignore_max_val_diff` is also set. Available since
                RedisTimeSeries version 1.12.0.
            ignore_max_val_diff:
                A non-negative floating point value, that sets an ignore threshold for
                added values. If the difference between the last value and the new value
                is lower than this threshold, the new entry is ignored. Only applicable
                if `duplicate_policy` is set to `last`, and if `ignore_max_time_diff` is
                also set. Available since RedisTimeSeries version 1.12.0.
            on_duplicate:
                Use a specific duplicate policy for the specified timestamp. Overrides
                the duplicate policy set by `duplicate_policy`.
        )	r'   r(   r)   r*   r+   r,   _append_on_duplicater-   ADD_CMD)r   r   r4   r5   r   r   r   r   r   r   r   r6   r/   r"   r"   r$   r8     s   
H
ktv_tuplesc                 C   r    r!   r"   r   r<   r"   r"   r$   madd`     zTimeSeriesCommands.maddc                 C   r    r!   r"   r=   r"   r"   r$   r>   f  r?   c                 C   s*   g }|D ]}| | q| jtg|R  S )ay  
        Append new samples to one or more time series.

        Each time series must already exist.

        The method expects a list of tuples. Each tuple should contain three elements:
        (`key`, `timestamp`, `value`). The `value` will be appended to the time series
        identified by 'key', at the given 'timestamp'.

        For more information see https://redis.io/commands/ts.madd/

        Args:
            ktv_tuples:
                A list of tuples, where each tuple contains:
                    - `key`: The key of the time series.
                    - `timestamp`: The timestamp at which the value should be appended.
                    - `value`: The value to append to the time series.

        Returns:
            A list that contains, for each sample, either the timestamp that was used,
            or an error, if the sample could not be added.
        )extendr-   MADD_CMD)r   r<   r/   ktvr"   r"   r$   r>   l  s   c                 C   r    r!   r"   r   r   r5   r4   r   r   r   r   r   r   r   r"   r"   r$   incrby     zTimeSeriesCommands.incrbyc                 C   r    r!   r"   rC   r"   r"   r$   rD     rE   c                 C   p   ||g}|  || | || | || | || | || | || | ||	|
 | jtg|R  S )a  
        Increment the latest sample's of a series. When the specified key does not
        exist, a new time series is created.

        This command can be used as a counter or gauge that automatically gets history
        as a time series.

        For more information see https://redis.io/commands/ts.incrby/

        Args:
            key:
                The time-series key.
            value:
                Numeric value to be added (addend).
            timestamp:
                Timestamp of the sample. `*` can be used for automatic timestamp (using
                the system clock). `timestamp` must be equal to or higher than the
                maximum existing timestamp in the series. When equal, the value of the
                sample with the maximum existing timestamp is increased. If it is
                higher, a new sample with a timestamp set to `timestamp` is created, and
                its value is set to the value of the sample with the maximum existing
                timestamp plus the addend.
            retention_msecs:
                Maximum age for samples, compared to the highest reported timestamp in
                milliseconds. If `None` or `0` is passed, the series is not trimmed at
                all.
            uncompressed:
                Changes data storage from compressed (default) to uncompressed.
            labels:
                A dictionary of label-value pairs that represent metadata labels of the
                key.
            chunk_size:
                Memory size, in bytes, allocated for each data chunk. Must be a multiple
                of 8 in the range `[48..1048576]`. In earlier versions of the module the
                minimum value was different.
            duplicate_policy:
                Policy for handling multiple samples with identical timestamps. Can be
                one of:

                - 'block': An error will occur and the new value will be ignored.
                - 'first': Ignore the new value.
                - 'last': Override with the latest value.
                - 'min': Only override if the value is lower than the existing value.
                - 'max': Only override if the value is higher than the existing value.
                - 'sum': If a previous sample exists, add the new sample to it so
                  that the updated value is equal to (previous + new). If no
                  previous sample exists, set the updated value equal to the new
                  value.

            ignore_max_time_diff:
                A non-negative integer value, in milliseconds, that sets an ignore
                threshold for added timestamps. If the difference between the last
                timestamp and the new timestamp is lower than this threshold, the new
                entry is ignored. Only applicable if `duplicate_policy` is set to
                `last`, and if `ignore_max_val_diff` is also set. Available since
                RedisTimeSeries version 1.12.0.
            ignore_max_val_diff:
                A non-negative floating point value, that sets an ignore threshold for
                added values. If the difference between the last value and the new value
                is lower than this threshold, the new entry is ignored. Only applicable
                if `duplicate_policy` is set to `last`, and if `ignore_max_time_diff` is
                also set. Available since RedisTimeSeries version 1.12.0.

        Returns:
            The timestamp of the sample that was modified or added.
        )	_append_timestampr'   r(   r)   r*   r+   r,   r-   
INCRBY_CMDr   r   r5   r4   r   r   r   r   r   r   r   r/   r"   r"   r$   rD        Oc                 C   r    r!   r"   rC   r"   r"   r$   decrby  rE   zTimeSeriesCommands.decrbyc                 C   r    r!   r"   rC   r"   r"   r$   rK     rE   c                 C   rF   )a  
        Decrement the latest sample's of a series. When the specified key does not
        exist, a new time series is created.

        This command can be used as a counter or gauge that automatically gets history
        as a time series.

        For more information see https://redis.io/commands/ts.decrby/

        Args:
            key:
                The time-series key.
            value:
                Numeric value to subtract (subtrahend).
            timestamp:
                Timestamp of the sample. `*` can be used for automatic timestamp (using
                the system clock). `timestamp` must be equal to or higher than the
                maximum existing timestamp in the series. When equal, the value of the
                sample with the maximum existing timestamp is decreased. If it is
                higher, a new sample with a timestamp set to `timestamp` is created, and
                its value is set to the value of the sample with the maximum existing
                timestamp minus subtrahend.
            retention_msecs:
                Maximum age for samples, compared to the highest reported timestamp in
                milliseconds. If `None` or `0` is passed, the series is not trimmed at
                all.
            uncompressed:
                Changes data storage from compressed (default) to uncompressed.
            labels:
                A dictionary of label-value pairs that represent metadata labels of the
                key.
            chunk_size:
                Memory size, in bytes, allocated for each data chunk. Must be a multiple
                of 8 in the range `[48..1048576]`. In earlier versions of the module the
                minimum value was different.
            duplicate_policy:
                Policy for handling multiple samples with identical timestamps. Can be
                one of:

                - 'block': An error will occur and the new value will be ignored.
                - 'first': Ignore the new value.
                - 'last': Override with the latest value.
                - 'min': Only override if the value is lower than the existing value.
                - 'max': Only override if the value is higher than the existing value.
                - 'sum': If a previous sample exists, add the new sample to it so
                  that the updated value is equal to (previous + new). If no
                  previous sample exists, set the updated value equal to the new
                  value.

            ignore_max_time_diff:
                A non-negative integer value, in milliseconds, that sets an ignore
                threshold for added timestamps. If the difference between the last
                timestamp and the new timestamp is lower than this threshold, the new
                entry is ignored. Only applicable if `duplicate_policy` is set to
                `last`, and if `ignore_max_val_diff` is also set. Available since
                RedisTimeSeries version 1.12.0.
            ignore_max_val_diff:
                A non-negative floating point value, that sets an ignore threshold for
                added values. If the difference between the last value and the new value
                is lower than this threshold, the new entry is ignored. Only applicable
                if `duplicate_policy` is set to `last`, and if `ignore_max_time_diff` is
                also set. Available since RedisTimeSeries version 1.12.0.

        Returns:
            The timestamp of the sample that was modified or added.
        )	rG   r'   r(   r)   r*   r+   r,   r-   
DECRBY_CMDrI   r"   r"   r$   rK   #  rJ   	from_timeto_timec                 C   r    r!   r"   r   r   rM   rN   r"   r"   r$   delete     zTimeSeriesCommands.deletec                 C   r    r!   r"   rO   r"   r"   r$   rP     rQ   c                 C   s   |  t|||S )aP  
        Delete all samples between two timestamps for a given time series.

        The given timestamp interval is closed (inclusive), meaning that samples whose
        timestamp equals `from_time` or `to_time` are also deleted.

        For more information see https://redis.io/commands/ts.del/

        Args:
            key:
                The time-series key.
            from_time:
                Start timestamp for the range deletion.
            to_time:
                End timestamp for the range deletion.

        Returns:
            The number of samples deleted.
        )r-   DEL_CMDrO   r"   r"   r$   rP     s   
source_keydest_keyaggregation_typebucket_size_msecalign_timestampc                 C   r    r!   r"   r   rS   rT   rU   rV   rW   r"   r"   r$   
createrule     zTimeSeriesCommands.createrulec                 C   r    r!   r"   rX   r"   r"   r$   rY     rZ   c                 C   s:   ||g}|  ||| |dur|| | jtg|R  S )aT  
        Create a compaction rule from values added to `source_key` into `dest_key`.

        For more information see https://redis.io/commands/ts.createrule/

        Args:
            source_key:
                Key name for source time series.
            dest_key:
                Key name for destination (compacted) time series.
            aggregation_type:
                Aggregation type: One of the following:
                [`avg`, `sum`, `min`, `max`, `range`, `count`, `first`, `last`, `std.p`,
                `std.s`, `var.p`, `var.s`, `twa`, 'countNaN', 'countAll']
            bucket_size_msec:
                Duration of each bucket, in milliseconds.
            align_timestamp:
                Assure that there is a bucket that starts at exactly align_timestamp and
                align all other buckets accordingly.
        N)_append_aggregationappendr-   CREATERULE_CMD)r   rS   rT   rU   rV   rW   r/   r"   r"   r$   rY     s
   
c                 C   r    r!   r"   r   rS   rT   r"   r"   r$   
deleterule  rQ   zTimeSeriesCommands.deleterulec                 C   r    r!   r"   r^   r"   r"   r$   r_     rQ   c                 C   s   |  t||S )z
        Delete a compaction rule from `source_key` to `dest_key`.

        For more information see https://redis.io/commands/ts.deleterule/
        )r-   DELETERULE_CMDr^   r"   r"   r$   r_     s   countfilter_by_tsfilter_by_min_valuefilter_by_max_valuealignlatestbucket_timestampemptyc                 C   sr   |||g}|  || | || | |||	 | || | ||
 | ||| | || | || |S )z*Create TS.RANGE and TS.REVRANGE arguments.)_append_latest_append_filer_by_ts_append_filer_by_value_append_count_append_alignr[   _append_bucket_timestamp_append_emptyr   r   rM   rN   ra   rU   rV   rb   rc   rd   re   rf   rg   rh   r/   r"   r"   r$   __range_params  s   
z!TimeSeriesCommands.__range_paramsr   c                 C   r    r!   r"   r   r   rM   rN   ra   rU   rV   rb   rc   rd   re   rf   rg   rh   r"   r"   r$   range     zTimeSeriesCommands.rangec                 C   r    r!   r"   rr   r"   r"   r$   rs     rt   c                 C   <   |  |||||||||	|
|||}| jtg|R d|giS )a  
        Query a range in forward direction for a specific time-series.

        For more information see https://redis.io/commands/ts.range/

        Args:
            key:
                Key name for timeseries.
            from_time:
                Start timestamp for the range query. `-` can be used to express the
                minimum possible timestamp (0).
            to_time:
                End timestamp for range query, `+` can be used to express the maximum
                possible timestamp.
            count:
                Limits the number of returned samples.
            aggregation_type:
                Optional aggregation type. Can be a single string or a list of strings
                for multiple aggregators (requires Redis 8.8+). Valid values:
                [`avg`, `sum`, `min`, `max`, `range`, `count`, `first`, `last`,
                `std.p`, `std.s`, `var.p`, `var.s`, `twa`, `countNaN`, `countAll`].
                When a list is passed, each sample in the response contains values
                in the same order as the specified aggregators.
            bucket_size_msec:
                Time bucket for aggregation in milliseconds.
            filter_by_ts:
                List of timestamps to filter the result by specific timestamps.
            filter_by_min_value:
                Filter result by minimum value (must mention also
                `filter by_max_value`).
            filter_by_max_value:
                Filter result by maximum value (must mention also
                `filter by_min_value`).
            align:
                Timestamp for alignment control for aggregation.
            latest:
                Used when a time series is a compaction, reports the compacted value of
                the latest possibly partial bucket.
            bucket_timestamp:
                Controls how bucket timestamps are reported. Can be one of [`-`, `low`,
                `+`, `high`, `~`, `mid`].
            empty:
                Reports aggregations for empty buckets.
        keys)!_TimeSeriesCommands__range_paramsr-   	RANGE_CMDrp   r"   r"   r$   rs   )  s    <c                 C   r    r!   r"   rr   r"   r"   r$   revrangev  rt   zTimeSeriesCommands.revrangec                 C   r    r!   r"   rr   r"   r"   r$   ry     rt   c                 C   ru   )aZ  
        Query a range in reverse direction for a specific time-series.

        **Note**: This command is only available since RedisTimeSeries >= v1.4

        For more information see https://redis.io/commands/ts.revrange/

        Args:
            key:
                Key name for timeseries.
            from_time:
                Start timestamp for the range query. `-` can be used to express the
                minimum possible timestamp (0).
            to_time:
                End timestamp for range query, `+` can be used to express the maximum
                possible timestamp.
            count:
                Limits the number of returned samples.
            aggregation_type:
                Optional aggregation type. Can be a single string or a list of strings
                for multiple aggregators (requires Redis 8.8+). Valid values:
                [`avg`, `sum`, `min`, `max`, `range`, `count`, `first`, `last`,
                `std.p`, `std.s`, `var.p`, `var.s`, `twa`, `countNaN`, `countAll`].
                When a list is passed, each sample in the response contains values
                in the same order as the specified aggregators.
            bucket_size_msec:
                Time bucket for aggregation in milliseconds.
            filter_by_ts:
                List of timestamps to filter the result by specific timestamps.
            filter_by_min_value:
                Filter result by minimum value (must mention also
                `filter_by_max_value`).
            filter_by_max_value:
                Filter result by maximum value (must mention also
                `filter_by_min_value`).
            align:
                Timestamp for alignment control for aggregation.
            latest:
                Used when a time series is a compaction, reports the compacted value of
                the latest possibly partial bucket.
            bucket_timestamp:
                Controls how bucket timestamps are reported. Can be one of [`-`, `low`,
                `+`, `high`, `~`, `mid`].
            empty:
                Reports aggregations for empty buckets.
        rv   )rw   r-   REVRANGE_CMDrp   r"   r"   r$   ry     s    >block_millisecondsblock_min_count	max_countc                 C   r    r!   r"   r   r   r4   r{   r|   r}   r"   r"   r$   read  rZ   zTimeSeriesCommands.readc                 C   r    r!   r"   r~   r"   r"   r$   r     rZ   c                 C   s<   ||g}|  ||| | || | jtg|R d|giS )a  
        Read a batch of samples with timestamps at or after `timestamp`, in
        ascending timestamp order.

        Without blocking, returns immediately with whatever qualifies (possibly an
        empty list). With the `block_milliseconds` group, waits until at least
        `block_min_count` qualifying samples exist or until the timeout elapses.
        This allows consuming historical and newly-appended samples continuously,
        in batches, without polling `TS.RANGE`.

        For more information see https://redis.io/commands/ts.read/

        Args:
            key:
                Key name for the time series (a regular series or a compaction
                destination).
            timestamp:
                Inclusive cursor. Samples with `timestamp >= timestamp` qualify.
                A non-negative integer (Unix milliseconds, `0` reads from the
                beginning) or one of the sentinels `-` (earliest), `+` (latest
                existing sample, inclusive) or `$` (only samples added after the
                command is received). Sentinels are sent to the server as-is and
                resolved server-side; `$` is only meaningful together with
                `block_milliseconds`, since nothing can qualify at execution time
                without blocking.
            block_milliseconds:
                Opt into blocking. Maximum time to wait, in whole milliseconds;
                a non-negative integer where `0` means wait indefinitely. When
                `None` (default) the command does not block.
            block_min_count:
                The unblock threshold: the call returns once this many samples
                qualify. A positive integer, defaulting to `1` when blocking is
                requested. Only used when `block_milliseconds` is set; the value is
                always emitted on the wire inside the BLOCK group.
            max_count:
                Reply cap, a positive integer. When more samples qualify than
                `max_count`, the oldest `max_count` are returned so callers can page
                forward. `None` (default) means unlimited.

        Returns:
            A list of `[timestamp, value]` samples in ascending timestamp order.
            An empty list is a successful reply (returned when nothing qualifies,
            or when a blocking call times out with nothing available).

        .. warning::
            A blocking call keeps the connection parked for up to
            `block_milliseconds`. The client's `socket_timeout` still applies: with
            the default (5 seconds) a longer block raises `TimeoutError` before the
            server replies. When using `block_milliseconds`, configure the client
            with a `socket_timeout` larger than the block window (or `None`), as with
            other blocking commands. This command must not be retried automatically
            after an empty or partial reply.
        rv   )_append_block_append_max_countr-   READ_CMD)r   r   r4   r{   r|   r}   r/   r"   r"   r$   r     s   =rv   aggregatorsc                 C   s   |st dt|g|||}| || | || | |||	 | || | ||
 | |||t| | || | 	|| |S )z,Create TS.NRANGE and TS.NREVRANGE arguments.z"At least one key must be provided.)
r	   lenri   rj   rk   rl   rm   _append_n_aggregationrn   ro   r   rv   rM   rN   ra   r   rV   rb   rc   rd   re   rf   rg   rh   r/   r"   r"   r$   __n_range_params@  s   z#TimeSeriesCommands.__n_range_paramsc                 C   r    r!   r"   r   rv   rM   rN   ra   r   rV   rb   rc   rd   re   rf   rg   rh   r"   r"   r$   nrangea  rt   zTimeSeriesCommands.nrangec                 C   r    r!   r"   r   r"   r"   r$   r   s  rt   c                 C   >   |  |||||||||	|
|||}| jtg|R dt|iS )aQ  
        Query an explicit list of time-series over a range in forward direction
        and return timestamp-major rows ordered by increasing timestamp.

        Each returned row is ``[timestamp, [value, ...]]``. With no aggregation
        -- or a single-aggregator spec per key -- the value array holds exactly
        one value per queried key, in the input ``keys`` order. When a per-key
        AGGREGATION spec lists several aggregators (e.g. ``"avg,max"``), that key
        contributes one value per aggregator in the order the aggregators were
        listed, and the row's value array is those per-key blocks concatenated in
        ``keys`` order. For example ``keys=[a, b]`` with
        ``aggregators=["avg,max", "sum"]`` yields ``[a_avg, a_max, b_sum]`` for
        every row. A key (or aggregator column) with no sample or aggregation
        bucket at a row's timestamp is reported as ``NaN``, which is
        indistinguishable from a stored or aggregated ``NaN``.

        All keys must hash to the same slot when used against a cluster; this
        command is routed as a single-shard, key command and is never split
        across shards.

        For more information see https://redis.io/commands/ts.nrange/

        Args:
            keys:
                Explicit list of time-series keys. Order and duplicate keys are
                significant: the output column order maps to the input key
                order, and duplicate keys produce repeated value columns.
            from_time:
                Start timestamp for the range query. `-` can be used to express
                the minimum possible timestamp (0).
            to_time:
                End timestamp for range query, `+` can be used to express the
                maximum possible timestamp.
            count:
                Limits the number of returned rows, applied after the
                merge in increasing-timestamp order.
            aggregators:
                Optional aggregation, with exactly one spec token per key (a
                single aggregator is never broadcast across keys). Each per-key
                spec is a string and may list several comma-separated
                aggregators, e.g. ``["avg,max", "sum"]`` builds
                ``AGGREGATION avg,max sum`` for two keys. A bare string is the
                spec for a single-key query; a number of specs that differs from
                ``keys`` raises ``DataError``. Valid aggregators: [`avg`, `sum`,
                `min`, `max`, `range`, `count`, `first`, `last`, `std.p`,
                `std.s`, `var.p`, `var.s`, `twa`, `countNaN`, `countAll`].
            bucket_size_msec:
                Time bucket for aggregation in milliseconds. Shared by all keys.
            filter_by_ts:
                List of timestamps to keep before merging.
            filter_by_min_value:
                Keep only values greater than or equal to this value before
                merging (must also set `filter_by_max_value`).
            filter_by_max_value:
                Keep only values less than or equal to this value before
                merging (must also set `filter_by_min_value`).
            align:
                Timestamp for alignment control for aggregation.
            latest:
                Used when a time series is a compaction, reports the compacted
                value of the latest possibly partial bucket.
            bucket_timestamp:
                Controls how bucket timestamps are reported. Can be one of
                [`-`, `low`, `+`, `high`, `~`, `mid`].
            empty:
                Reports aggregations for empty buckets.
        rv   )#_TimeSeriesCommands__n_range_paramsr-   
NRANGE_CMDlistr   r"   r"   r$   r         Sc                 C   r    r!   r"   r   r"   r"   r$   	nrevrange  rt   zTimeSeriesCommands.nrevrangec                 C   r    r!   r"   r   r"   r"   r$   r     rt   c                 C   r   )aT  
        Query an explicit list of time-series over a range in reverse direction
        and return timestamp-major rows ordered by decreasing timestamp.

        Each returned row is ``[timestamp, [value, ...]]``. With no aggregation
        -- or a single-aggregator spec per key -- the value array holds exactly
        one value per queried key, in the input ``keys`` order. When a per-key
        AGGREGATION spec lists several aggregators (e.g. ``"avg,max"``), that key
        contributes one value per aggregator in the order the aggregators were
        listed, and the row's value array is those per-key blocks concatenated in
        ``keys`` order. For example ``keys=[a, b]`` with
        ``aggregators=["avg,max", "sum"]`` yields ``[a_avg, a_max, b_sum]`` for
        every row. A key (or aggregator column) with no sample or aggregation
        bucket at a row's timestamp is reported as ``NaN``, which is
        indistinguishable from a stored or aggregated ``NaN``.

        All keys must hash to the same slot when used against a cluster; this
        command is routed as a single-shard, key command and is never split
        across shards.

        For more information see https://redis.io/commands/ts.nrevrange/

        Args:
            keys:
                Explicit list of time-series keys. Order and duplicate keys are
                significant: the output column order maps to the input key
                order, and duplicate keys produce repeated value columns.
            from_time:
                Start timestamp for the range query. `-` can be used to express
                the minimum possible timestamp (0).
            to_time:
                End timestamp for range query, `+` can be used to express the
                maximum possible timestamp.
            count:
                Limits the number of returned rows, applied after the
                merge in decreasing-timestamp order.
            aggregators:
                Optional aggregation, with exactly one spec token per key (a
                single aggregator is never broadcast across keys). Each per-key
                spec is a string and may list several comma-separated
                aggregators, e.g. ``["avg,max", "sum"]`` builds
                ``AGGREGATION avg,max sum`` for two keys. A bare string is the
                spec for a single-key query; a number of specs that differs from
                ``keys`` raises ``DataError``. Valid aggregators: [`avg`, `sum`,
                `min`, `max`, `range`, `count`, `first`, `last`, `std.p`,
                `std.s`, `var.p`, `var.s`, `twa`, `countNaN`, `countAll`].
            bucket_size_msec:
                Time bucket for aggregation in milliseconds. Shared by all keys.
            filter_by_ts:
                List of timestamps to keep before merging.
            filter_by_min_value:
                Keep only values greater than or equal to this value before
                merging (must also set `filter_by_max_value`).
            filter_by_max_value:
                Keep only values less than or equal to this value before
                merging (must also set `filter_by_min_value`).
            align:
                Timestamp for alignment control for aggregation.
            latest:
                Used when a time series is a compaction, reports the compacted
                value of the latest possibly partial bucket.
            bucket_timestamp:
                Controls how bucket timestamps are reported. Can be one of
                [`-`, `low`, `+`, `high`, `~`, `mid`].
            empty:
                Reports aggregations for empty buckets.
        rv   )r   r-   NREVRANGE_CMDr   r   r"   r"   r$   r     r   filterswith_labelsgroupbyreduceselect_labelsexclude_emptyc                 C   s   |durt |trt|dkrtd|r|durtd||g}| || | || | ||	|
 | ||| | || | 	|| | 
||| | || | || | || |dg ||7 }| ||| |S )z,Create TS.MRANGE and TS.MREVRANGE arguments.Nr   z>GROUPBY is not allowed when multiple aggregators are specifiedz(EXCLUDEEMPTY is not allowed with GROUPBYFILTER)
isinstancer   r   r	   ri   rj   rk   _append_with_labelsrl   rm   r[   rn   ro   _append_exclude_emptyr@   _append_groupby_reduce)r   rU   rV   ra   r   rM   rN   r   rb   rc   rd   r   r   r   re   rf   rg   rh   r   r/   r"   r"   r$   __mrange_paramsq  s0   z"TimeSeriesCommands.__mrange_paramsc                 C   r    r!   r"   r   rM   rN   r   ra   rU   rV   r   rb   rc   rd   r   r   r   re   rf   rg   rh   r   r"   r"   r$   mrange     zTimeSeriesCommands.mrangec                 C   r    r!   r"   r   r"   r"   r$   r     r   c                 C   D   |  |||||||||	|
||||||||}| jtg|R d|iS )ay  
        Query a range across multiple time-series by filters in forward direction.

        For more information see https://redis.io/commands/ts.mrange/

        Args:
            from_time:
                Start timestamp for the range query. `-` can be used to express the
                minimum possible timestamp (0).
            to_time:
                End timestamp for range query, `+` can be used to express the maximum
                possible timestamp.
            filters:
                Filter to match the time-series labels.
            count:
                Limits the number of returned samples.
            aggregation_type:
                Optional aggregation type. Can be a single string or a list of strings
                for multiple aggregators (requires Redis 8.8+). Valid values:
                [`avg`, `sum`, `min`, `max`, `range`, `count`, `first`, `last`,
                `std.p`, `std.s`, `var.p`, `var.s`, `twa`, `countNaN`, `countAll`].
                When a list is passed, each sample in the response contains values
                in the same order as the specified aggregators.
                Note: GROUPBY is not allowed when multiple aggregators are specified.
            bucket_size_msec:
                Time bucket for aggregation in milliseconds.
            with_labels:
                Include in the reply all label-value pairs representing metadata labels
                of the time series.
            filter_by_ts:
                List of timestamps to filter the result by specific timestamps.
            filter_by_min_value:
                Filter result by minimum value (must mention also
                `filter_by_max_value`).
            filter_by_max_value:
                Filter result by maximum value (must mention also
                `filter_by_min_value`).
            groupby:
                Grouping by fields the results (must mention also `reduce`).
            reduce:
                Applying reducer functions on each group. Can be one of [`avg` `sum`,
                `min`, `max`, `range`, `count`, `std.p`, `std.s`, `var.p`, `var.s`].
            select_labels:
                Include in the reply only a subset of the key-value pair labels of a
                series.
            align:
                Timestamp for alignment control for aggregation.
            latest:
                Used when a time series is a compaction, reports the compacted value of
                the latest possibly partial bucket.
            bucket_timestamp:
                Controls how bucket timestamps are reported. Can be one of [`-`, `low`,
                `+`, `high`, `~`, `mid`].
            empty:
                Reports aggregations for empty buckets.
            exclude_empty:
                Omit matching series whose reported samples array is empty for the
                queried range and options. Must not be combined with `groupby`.
        rU   )"_TimeSeriesCommands__mrange_paramsr-   
MRANGE_CMDr   rM   rN   r   ra   rU   rV   r   rb   rc   rd   r   r   r   re   rf   rg   rh   r   r/   r"   r"   r$   r     6   Pc                 C   r    r!   r"   r   r"   r"   r$   	mrevrange8  r   zTimeSeriesCommands.mrevrangec                 C   r    r!   r"   r   r"   r"   r$   r   O  r   c                 C   r   )a|  
        Query a range across multiple time-series by filters in reverse direction.

        For more information see https://redis.io/commands/ts.mrevrange/

        Args:
            from_time:
                Start timestamp for the range query. '-' can be used to express the
                minimum possible timestamp (0).
            to_time:
                End timestamp for range query, '+' can be used to express the maximum
                possible timestamp.
            filters:
                Filter to match the time-series labels.
            count:
                Limits the number of returned samples.
            aggregation_type:
                Optional aggregation type. Can be a single string or a list of strings
                for multiple aggregators (requires Redis 8.8+). Valid values:
                [`avg`, `sum`, `min`, `max`, `range`, `count`, `first`, `last`,
                `std.p`, `std.s`, `var.p`, `var.s`, `twa`, `countNaN`, `countAll`].
                When a list is passed, each sample in the response contains values
                in the same order as the specified aggregators.
                Note: GROUPBY is not allowed when multiple aggregators are specified.
            bucket_size_msec:
                Time bucket for aggregation in milliseconds.
            with_labels:
                Include in the reply all label-value pairs representing metadata labels
                of the time series.
            filter_by_ts:
                List of timestamps to filter the result by specific timestamps.
            filter_by_min_value:
                Filter result by minimum value (must mention also
                `filter_by_max_value`).
            filter_by_max_value:
                Filter result by maximum value (must mention also
                `filter_by_min_value`).
            groupby:
                Grouping by fields the results (must mention also `reduce`).
            reduce:
                Applying reducer functions on each group. Can be one of [`avg` `sum`,
                `min`, `max`, `range`, `count`, `std.p`, `std.s`, `var.p`, `var.s`].
            select_labels:
                Include in the reply only a subset of the key-value pair labels of a
                series.
            align:
                Timestamp for alignment control for aggregation.
            latest:
                Used when a time series is a compaction, reports the compacted value of
                the latest possibly partial bucket.
            bucket_timestamp:
                Controls how bucket timestamps are reported. Can be one of [`-`, `low`,
                `+`, `high`, `~`, `mid`].
            empty:
                Reports aggregations for empty buckets.
            exclude_empty:
                Omit matching series whose reported samples array is empty for the
                queried range and options. Must not be combined with `groupby`.
        rU   )r   r-   MREVRANGE_CMDr   r"   r"   r$   r   f  r   c                 C   r    r!   r"   r   r   rf   r"   r"   r$   get  rQ   zTimeSeriesCommands.getc                 C   r    r!   r"   r   r"   r"   r$   r     rQ   c                 C   s,   |g}|  || | jtg|R d|giS )a$  
        Get the last sample of `key`.

        For more information see https://redis.io/commands/ts.get/

        Args:
            latest:
                Used when a time series is a compaction, reports the compacted value of
                the latest (possibly partial) bucket.
        rv   )ri   r-   GET_CMD)r   r   rf   r/   r"   r"   r$   r     s   c                 C   r    r!   r"   r   r   r   r   rf   r"   r"   r$   mget     zTimeSeriesCommands.mgetc                 C   r    r!   r"   r   r"   r"   r$   r     r   c                 C   sD   g }|  || | ||| |dg ||7 }| jtg|R  S )a  
        Get the last samples matching the specific `filter`.

        For more information see https://redis.io/commands/ts.mget/

        Args:
            filters:
                Filter to match the time-series labels.
            with_labels:
                Include in the reply all label-value pairs representing metadata labels
                of the time series.
            select_labels:
                Include in the reply only a subset of the key-value pair labels o the
                time series.
            latest:
                Used when a time series is a compaction, reports the compacted value of
                the latest possibly partial bucket.
        r   )ri   r   r@   r-   MGET_CMD)r   r   r   r   rf   r/   r"   r"   r$   r     s   c                 C   r    r!   r"   r   r   r"   r"   r$   info  s   zTimeSeriesCommands.infoc                 C   r    r!   r"   r   r"   r"   r$   r   !  rQ   c                 C   s   | j t||gdS )zp
        Get information of `key`.

        For more information see https://redis.io/commands/ts.info/
        )rv   )r-   INFO_CMDr   r"   r"   r$   r   &     c                 C   r    r!   r"   r   r   r"   r"   r$   
queryindex0  rQ   zTimeSeriesCommands.queryindexc                 C   r    r!   r"   r   r"   r"   r$   r   5  rQ   c                 C   s   | j tg|R  S )z
        Get all time series keys matching the `filter` list.

        For more information see https://redis.io/commands/ts.queryindex/
        )r-   QUERYINDEX_CMDr   r"   r"   r$   r   :  r   labelc                 C   r    r!   r"   r   r   r   r"   r"   r$   querylabelsD     zTimeSeriesCommands.querylabelsc                 C   r    r!   r"   r   r"   r"   r$   r   K  r   c                 C   s6   |du rdg}nd|g}|  || | jtg|R  S )a  
        Get label metadata for the time series matching `filters`.

        The single `TS.QUERYLABELS` request is built from the supplied
        arguments:

        - When `label` is omitted (``None``), the ``LABELS`` form is issued and
          the reply is the set of all label names present on the matching (and
          readable) series, including the label names used in the filter
          itself.
        - When `label` is given, the ``VALUES`` form is issued and the reply is
          the set of all values assigned to `label` across the matching series.
          `label` is matched byte-exactly and is passed to the server without
          any normalization; a series that does not carry `label`, and a
          `label` that matches no series, contribute nothing (an empty reply,
          not an error).

        The reply is unordered and already deduplicated by the server, so it is
        returned as a Python ``set``. When `filters` is omitted (``None``), all
        indexed series are queried; filter expressions use the same language as
        `TS.QUERYINDEX` and are passed verbatim, while an explicitly empty
        collection raises a `DataError`.

        For more information see https://redis.io/commands/ts.querylabels/
        NLABELSVALUES)_append_filter_expressionsr-   QUERYLABELS_CMD)r   r   r   r/   r"   r"   r$   r   R  s
   r/   c                 C   s8   |du rdS t |}|std| d | | dS )a  Append the optional FILTER clause for TS.QUERYLABELS.

        ``None`` omits ``FILTER`` entirely (the documented all-series query);
        an explicitly empty collection is a local usage error, since silently
        widening to all series would be surprising. Any iterable is accepted and
        materialized once so single-pass iterators are handled correctly.
        Expressions are passed through verbatim, without parsing, reordering, or
        normalizing.
        NzMfilters cannot be an empty collection; pass None to query all indexed series.r   )r   r	   r\   r@   )r/   r   r"   r"   r$   r   u  s   
z-TimeSeriesCommands._append_filter_expressionsc                 C   s   |r|  ddg dS dS )z"Append UNCOMPRESSED tag to params.ENCODINGUNCOMPRESSEDNr@   )r/   r   r"   r"   r$   r(     s   z'TimeSeriesCommands._append_uncompressedc                 C   s<   |r|rt d|r| dg |r| dg| dS dS )z!Append labels behavior to params.z:with_labels and select_labels cannot be provided together.
WITHLABELSSELECTED_LABELSNr	   r@   )r/   r   r   r"   r"   r$   r     s   z&TimeSeriesCommands._append_with_labelsc                 C   s2   |dur|dur|  d|d| g dS dS dS )z)Append GROUPBY REDUCE property to params.NGROUPBYREDUCE)r@   upper)r/   r   r   r"   r"   r$   r     s   z)TimeSeriesCommands._append_groupby_reduce	retentionc                 C      |dur|  d|g dS dS )z$Append RETENTION property to params.N	RETENTIONr   )r/   r   r"   r"   r$   r'        z$TimeSeriesCommands._append_retentionc                 C   s6   |r|  d | D ]\}}| ||g qdS dS )z!Append LABELS property to params.r   N)r\   itemsr@   )r/   r   kvr"   r"   r$   r+     s   
z!TimeSeriesCommands._append_labelsc                 C   r   )z Append COUNT property to params.NCOUNTr   )r/   ra   r"   r"   r$   rl     r   z TimeSeriesCommands._append_countc                 C   s@   |du r|durt ddS |du rdn|}| d||g dS )a<  Append the BLOCK group to params.

        The BLOCK group is all-or-nothing: when blocking is requested
        (`block_milliseconds` is set), both `milliseconds` and `min_count` are
        always emitted, with `min_count` defaulting to 1. There is no standalone
        MIN_COUNT keyword in this command.
        NzYblock_min_count requires block_milliseconds to be set; the BLOCK group is all-or-nothing.r   BLOCKr   )r/   r{   r|   	min_countr"   r"   r$   r     s   z TimeSeriesCommands._append_blockc                 C   r   )z$Append MAX_COUNT property to params.N	MAX_COUNTr   )r/   r}   r"   r"   r$   r     r   z$TimeSeriesCommands._append_max_countc                 C   r   )z$Append TIMESTAMP property to params.N	TIMESTAMPr   )r/   r4   r"   r"   r$   rG     r   z$TimeSeriesCommands._append_timestampc                 C   r   )z Append ALIGN property to params.NALIGNr   )r/   re   r"   r"   r$   rm     r   z TimeSeriesCommands._append_alignc                 C   sD   |dur t |tr| dd||g dS | d||g dS dS )z&Append AGGREGATION property to params.NAGGREGATION,)r   r   r@   join)r/   rU   rV   r"   r"   r$   r[     s   
z&TimeSeriesCommands._append_aggregationnumkeysc                 C   sb   |du rdS t |tr|gnt|}t||kr%td| dt| d| dg|| dS )a  Append the AGGREGATION clause for TS.NRANGE / TS.NREVRANGE.

        These commands take exactly one aggregation spec token per queried key;
        a single aggregator is never broadcast across keys. A spec token may hold
        several comma-separated aggregators, so the wire form is e.g.
        ``AGGREGATION avg,max sum 1000`` for two keys -- key 0 aggregated by both
        ``avg`` and ``max``, key 1 by ``sum``. Pass one spec string per key, each
        optionally comma-joined (``["avg,max", "sum"]``); a bare string is the
        spec for a single-key query. (Matches RedisTimeSeries PR #2079, which
        replaced the earlier single comma-joined / broadcast token.)
        NzDAGGREGATION requires exactly one aggregation spec per key (expected z, got z8); a spec may list multiple comma-separated aggregators.r   )r   strr   r   r	   r@   )r/   r   rV   r   specsr"   r"   r$   r     s   z(TimeSeriesCommands._append_n_aggregationc                 C   r   )z%Append CHUNK_SIZE property to params.N
CHUNK_SIZEr   )r/   r   r"   r"   r$   r)     r   z%TimeSeriesCommands._append_chunk_sizec                 C   r   )z+Append DUPLICATE_POLICY property to params.NDUPLICATE_POLICYr   )r/   r   r"   r"   r$   r*        z+TimeSeriesCommands._append_duplicate_policyc                 C   r   )z'Append ON_DUPLICATE property to params.NON_DUPLICATEr   )r/   r6   r"   r"   r$   r:   #  r   z'TimeSeriesCommands._append_on_duplicatets_listc                 C   s    |dur|  dg| dS dS )z'Append FILTER_BY_TS property to params.NFILTER_BY_TSr   )r/   r   r"   r"   r$   rj   )  s   z&TimeSeriesCommands._append_filer_by_ts	min_value	max_valuec                 C   s,   |dur|dur|  d||g dS dS dS )z*Append FILTER_BY_VALUE property to params.NFILTER_BY_VALUEr   )r/   r   r   r"   r"   r$   rk   /  s   z)TimeSeriesCommands._append_filer_by_valuec                 C      |r	|  d dS dS )z!Append LATEST property to params.LATESTNr\   )r/   rf   r"   r"   r$   ri   7     z!TimeSeriesCommands._append_latestc                 C   r   )z+Append BUCKET_TIMESTAMP property to params.NBUCKETTIMESTAMPr   )r/   rg   r"   r"   r$   rn   =  r   z+TimeSeriesCommands._append_bucket_timestampc                 C   r   )z Append EMPTY property to params.EMPTYNr   )r/   rh   r"   r"   r$   ro   E  r   z TimeSeriesCommands._append_emptyc                 C   r   )z'Append EXCLUDEEMPTY property to params.EXCLUDEEMPTYNr   )r/   r   r"   r"   r$   r   K  r   z(TimeSeriesCommands._append_exclude_emptyc                 C   sL   |du |du krt d|dur"|dur$| dt|t|g dS dS dS )z#Append insertion filters to params.Nz>Both ignore_max_time_diff and ignore_max_val_diff must be set.IGNORE)
ValueErrorr@   r   )r/   r   r   r"   r"   r$   r,   Q  s   z,TimeSeriesCommands._append_insertion_filters)NFNNNNN)NNNNNN)NFNNNNNN)NNFNNNNNr!   )
NNr   NNNNFNF)NNN)NNr   FNNNNNNNFNFF)F)FNF)NN)L__name__
__module____qualname____doc__r   r   r   intboolr   r   r   r%   r
   r   r1   r8   r   r   r   r>   rD   rK   rP   rY   r_   rw   r   rs   ry   r   r   r   r   r   r   r   r   r   r   r   r   dictr   r   r   bytesr   r   setr   staticmethodr   r   r(   r   r   r'   r+   rl   r   r   rG   rm   r[   r   r)   r*   r:   rj   rk   ri   rn   ro   r   r,   r"   r"   r"   r$   r   )   s   	
	
	


H		
	
E	
	
	


U


	

	

	


\
	

	

	


\"	

#
	



	


	


	



M
	


	


	



O	

C
	


!
	


	


	



d
	


	


	



d
	



0
	



	



	




i
	



	



	




i





"$








#

$  r   N),typingr   r   r   r   r   r   r   redis.exceptionsr	   redis.typingr
   r   r   r   r   r   r   r   r   r   r   r;   r3   r]   r.   rL   r`   rR   r   rH   r   rA   r   r   r   r   r   r   r   rx   r   rz   r   r"   r"   r"   r$   <module>   s4   $ ,