File: //usr/lib/python3.9/site-packages/redis/commands/timeseries/__pycache__/commands.cpython-39.pyc
a
��bvn � @ sb d dl mZ dZdZdZdZdZdZdZd Z d
Z
dZdZd
Z
dZdZdZdZdZG dd� d�ZdS )� )� DataError�TS.ADDzTS.ALTERz
TS.CREATERULEz TS.CREATEz TS.DECRBYz
TS.DELETERULEzTS.DELzTS.GETz TS.INCRBYzTS.INFOzTS.MADDzTS.MGETz TS.MRANGEzTS.MREVRANGEz
TS.QUERYINDEXzTS.RANGEzTS.REVRANGEc @ sP e Zd ZdZdd� Zdd� Zdd� Zdd � Zd
d� Zdd
� Z dd� Z
dd� Zdd� Zdd� Z
dEdd�ZdFdd�Zdd� ZdGdd �ZdHd!d"�Zd#d$� ZdId%d&�Zd'd(� Zd)d*� Zed+d,� �ZedJd-d.��Zed/d0� �Zed1d2� �Zed3d4� �Zed5d6� �Zed7d8� �Zed9d:� �Zed;d<� �Z ed=d>� �Z!ed?d@� �Z"edAdB� �Z#edCdD� �Z$dS )K�TimeSeriesCommandszRedisTimeSeries Commands.c K s� |� dd�}|� dd�}|� di �}|� dd�}|� dd�}|g}| �||� | �||� | �||� | �|t|� | �||� | jtg|�R � S )af
Create a new time-series.
Args:
key:
time-series key
retention_msecs:
Maximum age for samples compared to last event time (in milliseconds).
If None or 0 is passed then the series is not trimmed at all.
uncompressed:
Since RedisTimeSeries v1.2, both timestamps and values are
compressed by default.
Adding this flag will keep data in an uncompressed form.
Compression not only saves
memory but usually improve performance due to lower number
of memory accesses.
labels:
Set of label-value pairs that represent metadata labels of the key.
chunk_size:
Each time-serie uses chunks of memory of fixed size for
time series samples.
You can alter the default TSDB chunk size by passing the
chunk_size argument (in Bytes).
duplicate_policy:
Since RedisTimeSeries v1.4 you can specify the duplicate sample policy
( Configure what to do on duplicate sample. )
Can be one of:
- 'block': an error will occur for any out of order sample.
- 'first': ignore the new value.
- 'last': override with 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.
When this is not set, the server-wide default will be used.
For more information: https://oss.redis.com/redistimeseries/commands/#tscreate
�retention_msecsN�uncompressedF�labels�
chunk_size�duplicate_policy)�get�_append_retention�_append_uncompressed�_append_chunk_size�_append_duplicate_policy�
CREATE_CMD�_append_labels�execute_command) �self�key�kwargsr r r r r �params� r �F/usr/lib/python3.9/site-packages/redis/commands/timeseries/commands.py�create s &zTimeSeriesCommands.createc K sb |� dd�}|� di �}|� dd�}|g}| �||� | �|t|� | �||� | jtg|�R � S )z�
Update the retention, labels of an existing key.
For more information see
The parameters are the same as TS.CREATE.
For more information: https://oss.redis.com/redistimeseries/commands/#tsalter
r Nr r )r
r r � ALTER_CMDr r )r r r r r r r r r r �alterM s zTimeSeriesCommands.alterc K s� |� dd�}|� dd�}|� di �}|� dd�}|� dd�} |||g}
| �|
|� | �|
|� | �|
|� | �|
t| � | �|
|� | jtg|
�R � S )a!
Append (or create and append) a new sample to the series.
For more information see
Args:
key:
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 last event time (in milliseconds).
If None or 0 is passed then the series is not trimmed at all.
uncompressed:
Since RedisTimeSeries v1.2, both timestamps and values are compressed by default.
Adding this flag will keep data in an uncompressed form. Compression not only saves
memory but usually improve performance due to lower number of memory accesses.
labels:
Set of label-value pairs that represent metadata labels of the key.
chunk_size:
Each time-serie uses chunks of memory of fixed size for time series samples.
You can alter the default TSDB chunk size by passing the chunk_size argument (in Bytes).
duplicate_policy:
Since RedisTimeSeries v1.4 you can specify the duplicate sample policy
(Configure what to do on duplicate sample).
Can be one of:
- 'block': an error will occur for any out of order sample.
- 'first': ignore the new value.
- 'last': override with 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.
When this is not set, the server-wide default will be used.
For more information: https://oss.redis.com/redistimeseries/master/commands/#tsadd
r Nr Fr r r )r
r r r
r �ADD_CMDr r )r r � timestamp�valuer r r r r r r r r r �add` s &
zTimeSeriesCommands.addc C s4 g }|D ]}|D ]}|� |� qq| jtg|�R � S )aH
Append (or create and append) a new `value` to series
`key` with `timestamp`.
Expects a list of `tuples` as (`key`,`timestamp`, `value`).
Return value is an array with timestamps of insertions.
For more information: https://oss.redis.com/redistimeseries/master/commands/#tsmadd
)�appendr �MADD_CMD)r Z
ktv_tuplesr Zktv�itemr r r �madd� s
zTimeSeriesCommands.maddc
K s� |� dd�}|� dd�}|� dd�}|� di �}|� dd�}||g} | �| |� | �| |� | �| |� | �| |� | �| |� | jtg| �R � S )aN
Increment (or create an time-series and increment) the latest
sample's of a series.
This command can be used as a counter or gauge that automatically gets
history as a time series.
Args:
key:
time-series key
value:
Numeric data value of the sample
timestamp:
Timestamp of the sample. None can be used for automatic timestamp (using the system clock).
retention_msecs:
Maximum age for samples compared to last event time (in milliseconds).
If None or 0 is passed then the series is not trimmed at all.
uncompressed:
Since RedisTimeSeries v1.2, both timestamps and values are compressed by default.
Adding this flag will keep data in an uncompressed form. Compression not only saves
memory but usually improve performance due to lower number of memory accesses.
labels:
Set of label-value pairs that represent metadata labels of the key.
chunk_size:
Each time-series uses chunks of memory of fixed size for time series samples.
You can alter the default TSDB chunk size by passing the chunk_size argument (in Bytes).
For more information: https://oss.redis.com/redistimeseries/master/commands/#tsincrbytsdecrby
r Nr r Fr r )r
�_append_timestampr r r
r r �
INCRBY_CMD�
r r r r r r r r r r r r r �incrby� s zTimeSeriesCommands.incrbyc
K s� |� dd�}|� dd�}|� dd�}|� di �}|� dd�}||g} | �| |� | �| |� | �| |� | �| |� | �| |� | jtg| �R � S )a~
Decrement (or create an time-series and decrement) the
latest sample's of a series.
This command can be used as a counter or gauge that
automatically gets history as a time series.
Args:
key:
time-series key
value:
Numeric data value of the sample
timestamp:
Timestamp of the sample. None can be used for automatic
timestamp (using the system clock).
retention_msecs:
Maximum age for samples compared to last event time (in milliseconds).
If None or 0 is passed then the series is not trimmed at all.
uncompressed:
Since RedisTimeSeries v1.2, both timestamps and values are
compressed by default.
Adding this flag will keep data in an uncompressed form.
Compression not only saves
memory but usually improve performance due to lower number
of memory accesses.
labels:
Set of label-value pairs that represent metadata labels of the key.
chunk_size:
Each time-series uses chunks of memory of fixed size for time series samples.
You can alter the default TSDB chunk size by passing the chunk_size argument (in Bytes).
For more information: https://oss.redis.com/redistimeseries/master/commands/#tsincrbytsdecrby
r Nr r Fr r )r
r# r r r
r r �
DECRBY_CMDr% r r r �decrby� s "zTimeSeriesCommands.decrbyc C s | � t|||�S )ao
Delete data points for a given timeseries and interval range
in the form of start and end delete timestamps.
The given timestamp interval is closed (inclusive), meaning start
and end data points will also be deleted.
Return the count for deleted items.
For more information see
Args:
key:
time-series key.
from_time:
Start timestamp for the range deletion.
to_time:
End timestamp for the range deletion.
For more information: https://oss.redis.com/redistimeseries/master/commands/#tsdel
)r �DEL_CMD)r r � from_time�to_timer r r �delete s zTimeSeriesCommands.deletec C s( ||g}| � |||� | jtg|�R � S )a�
Create a compaction rule from values added to `source_key` into `dest_key`.
Aggregating for `bucket_size_msec` where an `aggregation_type` can be
[`avg`, `sum`, `min`, `max`, `range`, `count`, `first`, `last`,
`std.p`, `std.s`, `var.p`, `var.s`]
For more information: https://oss.redis.com/redistimeseries/master/commands/#tscreaterule
)�_append_aggregationr �CREATERULE_CMD)r �
source_key�dest_key�aggregation_type�bucket_size_msecr r r r �
createrule s zTimeSeriesCommands.createrulec C s | � t||�S )z�
Delete a compaction rule.
For more information see
For more information: https://oss.redis.com/redistimeseries/master/commands/#tsdeleterule
)r �DELETERULE_CMD)r r/ r0 r r r �
deleterule$ s zTimeSeriesCommands.deleterulec C sN |||g}| � ||� | �||| � | �||� | �||
� | �|||� |S )z*Create TS.RANGE and TS.REVRANGE arguments.)�_append_filer_by_ts�_append_filer_by_value�
_append_count�
_append_alignr- �r r r* r+ �countr1 r2 �filter_by_ts�filter_by_min_value�filter_by_max_value�alignr r r r Z__range_params- s
z!TimeSeriesCommands.__range_paramsNr c C s. | � ||||||||| |
�
}| jtg|�R � S )a
Query a range in forward direction for a specific time-serie.
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:
Optional maximum number of returned results.
aggregation_type:
Optional aggregation type. Can be one of
[`avg`, `sum`, `min`, `max`, `range`, `count`,
`first`, `last`, `std.p`, `std.s`, `var.p`, `var.s`]
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.
For more information: https://oss.redis.com/redistimeseries/master/commands/#tsrangetsrevrange
)�!_TimeSeriesCommands__range_paramsr � RANGE_CMDr: r r r �rangeD s /�zTimeSeriesCommands.rangec C s. | � ||||||||| |
�
}| jtg|�R � S )a*
Query a range in reverse direction for a specific time-series.
**Note**: This command is only available since RedisTimeSeries >= v1.4
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:
Optional maximum number of returned results.
aggregation_type:
Optional aggregation type. Can be one of [`avg`, `sum`, `min`, `max`, `range`, `count`,
`first`, `last`, `std.p`, `std.s`, `var.p`, `var.s`]
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.
For more information: https://oss.redis.com/redistimeseries/master/commands/#tsrangetsrevrange
)r@ r �REVRANGE_CMDr: r r r �revrange� s ,�zTimeSeriesCommands.revrangec C s| ||g}| � ||� | �|| |
� | �||� | �||� | �|||� | �|||
� |�dg� ||7 }| �|||� |S )z,Create TS.MRANGE and TS.MREVRANGE arguments.�FILTER)r6 r7 r8 r9 r- �_append_with_labels�extend�_append_groupby_reduce)r r1 r2 r; �filtersr* r+ �with_labelsr<