Trait TimeSeriesCommands

Source
pub trait TimeSeriesCommands<'a> {
Show 17 methods // Provided methods fn ts_add( self, key: impl SingleArg, timestamp: impl SingleArg, value: f64, options: TsAddOptions, ) -> PreparedCommand<'a, Self, u64> where Self: Sized { ... } fn ts_alter( self, key: impl SingleArg, options: TsCreateOptions, ) -> PreparedCommand<'a, Self, ()> where Self: Sized { ... } fn ts_create( self, key: impl SingleArg, options: TsCreateOptions, ) -> PreparedCommand<'a, Self, ()> where Self: Sized { ... } fn ts_createrule( self, src_key: impl SingleArg, dst_key: impl SingleArg, aggregator: TsAggregationType, bucket_duration: u64, options: TsCreateRuleOptions, ) -> PreparedCommand<'a, Self, ()> where Self: Sized { ... } fn ts_decrby( self, key: impl SingleArg, value: f64, options: TsIncrByDecrByOptions, ) -> PreparedCommand<'a, Self, ()> where Self: Sized { ... } fn ts_del( self, key: impl SingleArg, from_timestamp: u64, to_timestamp: u64, ) -> PreparedCommand<'a, Self, usize> where Self: Sized { ... } fn ts_deleterule( self, src_key: impl SingleArg, dst_key: impl SingleArg, ) -> PreparedCommand<'a, Self, ()> where Self: Sized { ... } fn ts_get( self, key: impl SingleArg, options: TsGetOptions, ) -> PreparedCommand<'a, Self, Option<(u64, f64)>> where Self: Sized { ... } fn ts_incrby( self, key: impl SingleArg, value: f64, options: TsIncrByDecrByOptions, ) -> PreparedCommand<'a, Self, u64> where Self: Sized { ... } fn ts_info( self, key: impl SingleArg, debug: bool, ) -> PreparedCommand<'a, Self, TsInfoResult> where Self: Sized { ... } fn ts_madd<K: SingleArg, T: SingleArg, R: CollectionResponse<u64>>( self, items: impl MultipleArgsCollection<(K, T, f64)>, ) -> PreparedCommand<'a, Self, R> where Self: Sized { ... } fn ts_mget<F: SingleArg, R: KeyValueCollectionResponse<String, TsSample>>( self, options: TsMGetOptions, filters: impl SingleArgCollection<F>, ) -> PreparedCommand<'a, Self, R> where Self: Sized { ... } fn ts_mrange<F: SingleArg, R: KeyValueCollectionResponse<String, TsRangeSample>>( self, from_timestamp: impl SingleArg, to_timestamp: impl SingleArg, options: TsMRangeOptions, filters: impl SingleArgCollection<F>, groupby_options: TsGroupByOptions, ) -> PreparedCommand<'a, Self, R> where Self: Sized { ... } fn ts_mrevrange<F: SingleArg, R: KeyValueCollectionResponse<String, TsRangeSample>>( self, from_timestamp: impl SingleArg, to_timestamp: impl SingleArg, options: TsMRangeOptions, filters: impl SingleArgCollection<F>, groupby_options: TsGroupByOptions, ) -> PreparedCommand<'a, Self, R> where Self: Sized { ... } fn ts_queryindex<F: SingleArg, R: PrimitiveResponse + DeserializeOwned, RR: CollectionResponse<R>>( self, filters: impl SingleArgCollection<F>, ) -> PreparedCommand<'a, Self, RR> where Self: Sized { ... } fn ts_range<R: CollectionResponse<(u64, f64)>>( self, key: impl SingleArg, from_timestamp: impl SingleArg, to_timestamp: impl SingleArg, options: TsRangeOptions, ) -> PreparedCommand<'a, Self, R> where Self: Sized { ... } fn ts_revrange<R: CollectionResponse<(u64, f64)>>( self, key: impl SingleArg, from_timestamp: impl SingleArg, to_timestamp: impl SingleArg, options: TsRangeOptions, ) -> PreparedCommand<'a, Self, R> where Self: Sized { ... }
}
Expand description

A group of Redis commands related to Time Series

§See Also

Time Series Commands

Provided Methods§

Source

fn ts_add( self, key: impl SingleArg, timestamp: impl SingleArg, value: f64, options: TsAddOptions, ) -> PreparedCommand<'a, Self, u64>
where Self: Sized,

Append a sample to a time series

§Arguments
  • key - key name for the time series.
  • timestamp - UNIX sample timestamp in milliseconds or * to set the timestamp according to the server clock.
  • values - numeric data value of the sample. The double number should follow RFC 7159 (JSON standard). In particular, the parser rejects overly large values that do not fit in binary64. It does not accept NaN or infinite values.
§Return

The UNIX sample timestamp in milliseconds

§Notes
  • When specified key does not exist, a new time series is created.
  • if a COMPACTION_POLICY configuration parameter is defined, compacted time series would be created as well.
  • If timestamp is older than the retention period compared to the maximum existing timestamp, the sample is discarded and an error is returned.
  • When adding a sample to a time series for which compaction rules are defined:
    • If all the original samples for an affected aggregated time bucket are available, the compacted value is recalculated based on the reported sample and the original samples.
    • If only a part of the original samples for an affected aggregated time bucket is available due to trimming caused in accordance with the time series RETENTION policy, the compacted value is recalculated based on the reported sample and the available original samples.
    • If the original samples for an affected aggregated time bucket are not available due to trimming caused in accordance with the time series RETENTION policy, the compacted value bucket is not updated.
  • Explicitly adding samples to a compacted time series (using ts_add, ts_madd, ts_incrby, or ts_decrby) may result in inconsistencies between the raw and the compacted data. The compaction process may override such samples.
§Complexity

If a compaction rule exits on a time series, the performance of ts_add can be reduced. The complexity of ts_add is always O(M), where M is the number of compaction rules or O(1) with no compaction.

§See Also
Source

fn ts_alter( self, key: impl SingleArg, options: TsCreateOptions, ) -> PreparedCommand<'a, Self, ()>
where Self: Sized,

Update the retention, chunk size, duplicate policy, and labels of an existing time series

§Arguments
  • key - key name for the time series.
  • options - options to alter the existing time series. encoding cannot be used on this command.
§Notes

This command alters only the specified element. For example, if you specify only retention and labels, the chunk size and the duplicate policy are not altered.

§See Also
Source

fn ts_create( self, key: impl SingleArg, options: TsCreateOptions, ) -> PreparedCommand<'a, Self, ()>
where Self: Sized,

Create a new time series

§Arguments
  • key - key name for the time series.
§Notes
  • If a key already exists, you get a Redis error reply, TSDB: key already exists. You can check for the existence of a key with the exists command.
  • Other commands that also create a new time series when called with a key that does not exist are ts_add, ts_incrby, and ts_decrby.
§See Also
Source

fn ts_createrule( self, src_key: impl SingleArg, dst_key: impl SingleArg, aggregator: TsAggregationType, bucket_duration: u64, options: TsCreateRuleOptions, ) -> PreparedCommand<'a, Self, ()>
where Self: Sized,

Create a compaction rule

§Arguments
  • src_key - key name for the source time series.
  • dst_key - key name for destination (compacted) time series. It must be created before ts_createrule is called.
  • aggregator - aggregates results into time buckets by taking an aggregation type
  • bucket_duration - duration of each aggregation bucket, in milliseconds.
  • options - See TsCreateRuleOptions
§Notes
  • Only new samples that are added into the source series after the creation of the rule will be aggregated.
  • Calling ts_createrule with a nonempty dst_key may result in inconsistencies between the raw and the compacted data.
  • Explicitly adding samples to a compacted time series (using ts_add, ts_madd, ts_incrby, or ts_decrby) may result in inconsistencies between the raw and the compacted data. The compaction process may override such samples.
  • If no samples are added to the source time series during a bucket period. no compacted sample is added to the destination time series.
  • The timestamp of a compacted sample added to the destination time series is set to the start timestamp the appropriate compaction bucket. For example, for a 10-minute compaction bucket with no alignment, the compacted samples timestamps are x:00, x:10, x:20, and so on.
§See Also
Source

fn ts_decrby( self, key: impl SingleArg, value: f64, options: TsIncrByDecrByOptions, ) -> PreparedCommand<'a, Self, ()>
where Self: Sized,

Decrease the value of the sample with the maximum existing timestamp, or create a new sample with a value equal to the value of the sample with the maximum existing timestamp with a given decrement

§Arguments
  • key - key name for the time series.
  • value - numeric data value of the sample
  • options - See TsIncrByDecrByOptions
§Notes
  • When specified key does not exist, a new time series is created.
  • You can use this command as a counter or gauge that automatically gets history as a time series.
  • Explicitly adding samples to a compacted time series (using ts_add, ts_madd, ts_incrby, or ts_decrby) may result in inconsistencies between the raw and the compacted data. The compaction process may override such samples.
§See Also
Source

fn ts_del( self, key: impl SingleArg, from_timestamp: u64, to_timestamp: u64, ) -> PreparedCommand<'a, Self, usize>
where Self: Sized,

Delete all samples between two timestamps for a given time series

§Arguments
  • key - key name for the time series.
  • from_timestamp - start timestamp for the range deletion.
  • to_timestamp - end timestamp for the range deletion.
§Return

The number of samples that were removed.

§Notes

The given timestamp interval is closed (inclusive), meaning that samples whose timestamp equals the from_timestamp or to_timestamp are also deleted.

§See Also
Source

fn ts_deleterule( self, src_key: impl SingleArg, dst_key: impl SingleArg, ) -> PreparedCommand<'a, Self, ()>
where Self: Sized,

Delete a compaction rule

§Arguments
  • src_key - key name for the source time series.
  • dst_key - key name for destination (compacted) time series.
§Notes

This command does not delete the compacted series.

§See Also
Source

fn ts_get( self, key: impl SingleArg, options: TsGetOptions, ) -> PreparedCommand<'a, Self, Option<(u64, f64)>>
where Self: Sized,

Get the last sample

§Arguments
  • key - key name for the time series.
  • options - See TsGetOptions
§Return

An option tuple:

  • The last sample timestamp, and last sample value, when the time series contains data.
  • None, when the time series is empty.
§See Also
Source

fn ts_incrby( self, key: impl SingleArg, value: f64, options: TsIncrByDecrByOptions, ) -> PreparedCommand<'a, Self, u64>
where Self: Sized,

Increase the value of the sample with the maximum existing timestamp, or create a new sample with a value equal to the value of the sample with the maximum existing timestamp with a given increment

§Arguments
  • key - key name for the time series.
  • value - numeric data value of the sample
  • options - See TsIncrByDecrByOptions
§Notes
  • When specified key does not exist, a new time series is created.
  • You can use this command as a counter or gauge that automatically gets history as a time series.
  • Explicitly adding samples to a compacted time series (using ts_add, ts_madd, ts_incrby, or ts_decrby) may result in inconsistencies between the raw and the compacted data. The compaction process may override such samples.
§See Also
Source

fn ts_info( self, key: impl SingleArg, debug: bool, ) -> PreparedCommand<'a, Self, TsInfoResult>
where Self: Sized,

Return information and statistics for a time series.

§Arguments
  • key - key name for the time series.
  • debug - an optional flag to get a more detailed information about the chunks.
§Return

an instance of TsInfoResult

§See Also
Source

fn ts_madd<K: SingleArg, T: SingleArg, R: CollectionResponse<u64>>( self, items: impl MultipleArgsCollection<(K, T, f64)>, ) -> PreparedCommand<'a, Self, R>
where Self: Sized,

Append new samples to one or more time series

§Arguments
  • items - one or more the following tuple:
    • key - the key name for the time series.
    • timestamp - the UNIX sample timestamp in milliseconds or * to set the timestamp according to the server clock.
    • value - numeric data value of the sample (double).
      The double number should follow RFC 7159 (a JSON standard). The parser rejects overly large values that would not fit in binary64. It does not accept NaN or infinite values.
§Return

a collection of the timestamps of added samples

§Notes
  • If timestamp is older than the retention period compared to the maximum existing timestamp, the sample is discarded and an error is returned.
  • Explicitly adding samples to a compacted time series (using ts_add, ts_madd, ts_incrby, or ts_decrby) may result in inconsistencies between the raw and the compacted data. The compaction process may override such samples.
§See Also
Source

fn ts_mget<F: SingleArg, R: KeyValueCollectionResponse<String, TsSample>>( self, options: TsMGetOptions, filters: impl SingleArgCollection<F>, ) -> PreparedCommand<'a, Self, R>
where Self: Sized,

Get the last samples matching a specific filter

§Arguments
  • key - key name for the time series.
  • options - See TsMGetOptions
  • filters - filters time series based on their labels and label values, with these options:
    • label=value, where label equals value
    • label!=value, where label does not equal value
    • label=, where key does not have label label
    • label!=, where key has label label
    • label=(_value1_,_value2_,...), where key with label label equals one of the values in the list
    • label!=(value1,value2,...) where key with label label does not equal any of the values in the list
§Return

A collection of TsSample

§Notes
  • When using filters, apply a minimum of one label=value filter.
  • Filters are conjunctive. For example, the FILTER type=temperature room=study means the time series is a temperature time series of a study room.
§See Also
Source

fn ts_mrange<F: SingleArg, R: KeyValueCollectionResponse<String, TsRangeSample>>( self, from_timestamp: impl SingleArg, to_timestamp: impl SingleArg, options: TsMRangeOptions, filters: impl SingleArgCollection<F>, groupby_options: TsGroupByOptions, ) -> PreparedCommand<'a, Self, R>
where Self: Sized,

Query a range across multiple time series by filters in forward direction

§Arguments
  • from_timestamp - start timestamp for the range query (integer UNIX timestamp in milliseconds) or - to denote the timestamp of the earliest sample in the time series.
  • to_timestamp - end timestamp for the range query (integer UNIX timestamp in milliseconds) or + to denote the timestamp of the latest sample in the time series.
  • options - See TsMRangeOptions
  • filters - filters time series based on their labels and label values, with these options:
    • label=value, where label equals value
    • label!=value, where label does not equal value
    • label=, where key does not have label label
    • label!=, where key has label label
    • label=(_value1_,_value2_,...), where key with label label equals one of the values in the list
    • label!=(value1,value2,...) where key with label label does not equal any of the values in the list
  • groupby_options - See TsGroupByOptions
§Return

A collection of TsRangeSample

§Notes
  • The ts_mrange command cannot be part of transaction when running on a Redis cluster.
§See Also
Source

fn ts_mrevrange<F: SingleArg, R: KeyValueCollectionResponse<String, TsRangeSample>>( self, from_timestamp: impl SingleArg, to_timestamp: impl SingleArg, options: TsMRangeOptions, filters: impl SingleArgCollection<F>, groupby_options: TsGroupByOptions, ) -> PreparedCommand<'a, Self, R>
where Self: Sized,

Query a range across multiple time series by filters in reverse direction

§Arguments
  • from_timestamp - start timestamp for the range query (integer UNIX timestamp in milliseconds) or - to denote the timestamp of the earliest sample in the time series.
  • to_timestamp - end timestamp for the range query (integer UNIX timestamp in milliseconds) or + to denote the timestamp of the latest sample in the time series.
  • options - See TsMRangeOptions
  • filters - filters time series based on their labels and label values, with these options:
    • label=value, where label equals value
    • label!=value, where label does not equal value
    • label=, where key does not have label label
    • label!=, where key has label label
    • label=(_value1_,_value2_,...), where key with label label equals one of the values in the list
    • label!=(value1,value2,...) where key with label label does not equal any of the values in the list
  • groupby_options - See TsGroupByOptions
§Return

A collection of TsRangeSample

§Notes
  • The ts_mrevrange command cannot be part of transaction when running on a Redis cluster.
§See Also
Source

fn ts_queryindex<F: SingleArg, R: PrimitiveResponse + DeserializeOwned, RR: CollectionResponse<R>>( self, filters: impl SingleArgCollection<F>, ) -> PreparedCommand<'a, Self, RR>
where Self: Sized,

Get all time series keys matching a filter list

§Arguments
  • filters - filters time series based on their labels and label values, with these options:
    • label=value, where label equals value
    • label!=value, where label does not equal value
    • label=, where key does not have label label
    • label!=, where key has label label
    • label=(_value1_,_value2_,...), where key with label label equals one of the values in the list
    • label!=(value1,value2,...) where key with label label does not equal any of the values in the list
§Return

A collection of keys

§Notes
  • When using filters, apply a minimum of one label=value filter.
  • ts_queryindex cannot be part of a transaction that runs on a Redis cluster.
  • Filters are conjunctive. For example, the FILTER type=temperature room=study means the a time series is a temperature time series of a study room.
§See Also
Source

fn ts_range<R: CollectionResponse<(u64, f64)>>( self, key: impl SingleArg, from_timestamp: impl SingleArg, to_timestamp: impl SingleArg, options: TsRangeOptions, ) -> PreparedCommand<'a, Self, R>
where Self: Sized,

Query a range in forward direction

§Arguments
  • key - the key name for the time series.
  • from_timestamp - start timestamp for the range query (integer UNIX timestamp in milliseconds) or -to denote the timestamp of the earliest sample in the time series.
  • to_timestamp - end timestamp for the range query (integer UNIX timestamp in milliseconds) or + to denote the timestamp of the latest sample in the time series.
  • options - See TsRangeOptions
§Return

A collection of keys

§Notes
  • When the time series is a compaction, the last compacted value may aggregate raw values with timestamp beyond to_timestamp. That is because to_timestamp only limits the timestamp of the compacted value, which is the start time of the raw bucket that was compacted.
§See Also
Source

fn ts_revrange<R: CollectionResponse<(u64, f64)>>( self, key: impl SingleArg, from_timestamp: impl SingleArg, to_timestamp: impl SingleArg, options: TsRangeOptions, ) -> PreparedCommand<'a, Self, R>
where Self: Sized,

Query a range in reverse direction

§Arguments
  • key - the key name for the time series.
  • from_timestamp - start timestamp for the range query (integer UNIX timestamp in milliseconds) or -to denote the timestamp of the earliest sample in the time series.
  • to_timestamp - end timestamp for the range query (integer UNIX timestamp in milliseconds) or + to denote the timestamp of the latest sample in the time series.
  • options - See TsRangeOptions
§Return

A collection of keys

§Notes
  • When the time series is a compaction, the last compacted value may aggregate raw values with timestamp beyond to_timestamp. That is because to_timestamp only limits the timestamp of the compacted value, which is the start time of the raw bucket that was compacted.
§See Also

Implementors§

Source§

impl<'a> TimeSeriesCommands<'a> for &'a Client

Source§

impl<'a> TimeSeriesCommands<'a> for &'a mut Pipeline<'_>

Source§

impl<'a> TimeSeriesCommands<'a> for &'a mut Transaction