TairTS is a time series data structure that is developed on top of a Redis module. This data structure provides low-latency and high-concurrency in-memory read and write access, supports fast filtering and aggregate queries, and has both storage and computing capabilities. TairTS simplifies the processing of time series data and significantly improves performance.
Overview
Compared with RedisTimeSeries, TairTS provides a richer set of features:
Pkey-level aggregation. TairTS introduces the pkey structure as an additional hash layer to facilitate aggregate queries across multiple timelines.
For example, you can create multiple skeys that are named after metric names and device IDs in the foo pkey. Examples: temperature:1, pressure:1, and distance:1. Then, you can run the EXTS.S.MRANGE command provided by TairTS to retrieve custom monitoring data such as skeys that have a device ID of 1. If you want to implement a similar feature by using RedisTimeSeries, you must insert a large number of aggregate queries into business logic code.
The following section describes the structure of TairTS data:
Pkey: a piece of TairTS data that represents a set of timelines. A pkey can consist of multiple skeys.
Skey: a timeline. An skey can consist of multiple chunks that have a fixed capacity. You can attach one or more different labels to each skey. Then, skeys can be filtered by label.
Chunk: a data chunk. A chunk can store multiple data points.
A chunk can have a custom capacity of up to 256 data points.
Chunks serve as the smallest unit for data eviction. A chunk is deleted after all data points in the chunk expire.
DataPoint: a piece of time series data that includes a timestamp and a DOUBLE-type value.
Aggregate queries in scenarios such as downsampling, attribute filtering, batch query, and the use of multiple numerical functions. This feature integrates batch query and aggregation in a single command to reduce network interaction and provide responses within milliseconds.
Update or accumulation of historical time series data.
Configuration of time-to-live (TTL) for skeys. A TTL can be configured for each skey, enabling data to be automatically purged and the timeline to advance based on predefined time windows.
Efficient compression with the Gorilla algorithm. TairTS uses the Gorilla compression algorithm and specific storage techniques to significantly reduce storage costs.
Typical scenarios
Storage and computing of monitoring data
Per-second monitoring for application performance management (APM)
Data analysis and processing for IoT
Risk control in throttling scenarios
Caching of hot news
Use of time window functions
Best practices
Prerequisites
The instance that you want to manage is a Tair DRAM-based instance.
If the instance is a DRAM-based instance that is compatible with Redis 5.0, the minor version of the instance must be 1.7.20 or later.
The latest minor version provides more features and higher stability. We recommend that you update the instance to the latest minor version. For more information, see Update the minor version of an instance. If your instance is a cluster instance or read/write splitting instance, we recommend that you update the proxy nodes in the instance to the latest minor version to ensure that all commands can be run as expected.
Precautions
The TairTS data that you want to manage is stored on a Tair instance.
TairTS supports real-time, high-concurrency writes and queries but provides limited storage capacity. We recommend that you specify TTL for TairTS data to ensure that expired data is deleted in a timely manner.
To reduce storage costs, we recommend that you specify the
CHUNK_SIZE
parameter in the following ways:If an skey contains more than 5,000 data points on average, set
CHUNK_SIZE
to 256. This is the default value.If an skey contains less than 5,000 data points on average, set
CHUNK_SIZE
to a value that is calculated by using the following formula: Chunk size = Average number of data points of an skey/20. If an skey contains 1,000 data points on average, setCHUNK_SIZE
to 50.
Breaking changes:
On July 22, 2024, the 24.7.0.0 version of Tair DRAM-based instances that are compatible with Redis 6.0 was released. This version introduces a new parameter called ts-auto-del-empty-skey-enable, which is set to yes by default. This indicates that when all data points in an skey expire, the skey is automatically deleted. However, in versions prior to 24.7.0.0 of Tair DRAM-based instances that are compatible with Redis 6.0, skeys whose data points expire are not deleted by default.
Before you use TairTS on a Tair DRAM-based instance that is compatible with Redis 6.0, we recommend that you upgrade the instance to version 24.7.0.0 or later, and confirm and manually adjust the ts-auto-del-empty-skey-enable parameter settings. This can prevent any potential impact on your business due to the change in default behavior.
Supported commands
Table 1. TairTS commands
Type | Command | Syntax | Description |
Basic write operations |
| Creates a TairTS pkey. If a pkey with the same name already exists, the pkey cannot be created. | |
| Creates an skey in a specified pkey. If the pkey does not exist, it is automatically created. If an skey with the same name already exists, the skey cannot be created. Note You can specify parameters for the skey, such as the expiration time and whether to enable compression. | ||
| Modifies the metadata of a specified skey. Only the DATA_ET time value can be modified. | ||
| Inserts a data point into an skey. If the pkey or skey does not exist, the pkey or skey is automatically created. The parameters for the skey, such as the expiration time and whether to enable compression, take effect only if the skey is automatically created. | ||
| Inserts a data point into multiple skeys of a pkey. If the pkey or an skey does not exist, the pkey or skey is automatically created. The parameters for an skey, such as the expiration time and whether to enable compression, take effect only if the skey is automatically created. | ||
| Inserts a data point into an skey. If the data point that you want to insert has a positive value, the inserted value is added to the value of the last data point that exists in the skey. If the data point has a negative value, the inserted value is subtracted from the value of the last data point that exists in the skey. If the pkey or skey does not exist, the pkey or skey is automatically created. The default initial value is 0. The parameters for the skey, such as the expiration time and whether to enable compression, take effect only if the skey is automatically created. | ||
| Inserts a data point into multiple skeys of a pkey. If the data point that you want to insert has a positive value, the inserted value is added to the value of the last data point that exists in each skey. If the data point has a negative value, the inserted value is subtracted from the value of the last data point that exists in each skey. If the pkey or an skey does not exist, the pkey or skey is automatically created. The default initial value is 0. The parameters for an skey, such as the expiration time and whether to enable compression, take effect only if the skey is automatically created. | ||
| Deletes an skey and all data points in the skey from a pkey. | ||
Basic read operations |
| Queries the value of the last data point in a specified skey. | |
| Queries the metadata of a specified skey. The metadata includes the number of data points, the timestamp and value of the last data point, and the label information of the skey. | ||
| Queries the skeys that meet specified filter conditions in a pkey. | ||
Aggregate operations |
| Queries the number of data points that exist in an skey during a specified time range. The time range is a closed interval. | |
| Queries the number of data points that meet specified filter conditions in multiple skeys during a specified time range. The time range is a closed interval. | ||
| Aggregates data points in a pkey that meet specified filter conditions. If you specify one or more skeys for aggregation, the skeys are first aggregated in the same manner as when the EXTS.S.MRANGE command is used. Then, pkeys are aggregated based on the skey aggregation results. | ||
Concurrent write operations |
| Modifies the value of a data point in a specified skey. If the pkey or skey does not exist, the pkey or skey is automatically created. The parameters for the skey, such as the expiration time and whether to enable compression, take effect only if the skey is automatically created. | |
| Modifies the value of a data point in multiple skeys at a time. If the pkey or an skey does not exist, the pkey or skey is automatically created. The parameters for an skey, such as the expiration time and whether to enable compression, take effect only if the skey is automatically created. | ||
| Modifies the value of a data point in a specified skey. You can specify an increment or a decrement by which to modify the value. If the pkey or skey does not exist, the pkey or skey is automatically created. The default initial value is 0. The parameters for the skey, such as the expiration time and whether to enable compression, take effect only if the skey is automatically created. | ||
| Modifies the value of a data point in multiple skeys at a time. You can specify an increment or a decrement by which to modify the values. If the pkey or an skey does not exist, the pkey or skey is automatically created. The parameters for an skey, such as the expiration time and whether to enable compression, take effect only if the skey is automatically created. | ||
General-purpose operations |
| Deletes one or more TairTS keys. |
The following list describes the conventions for the command syntax used in this topic:
Uppercase keyword
: indicates the command keyword.Italic text
: indicates variables.[options]
: indicates that the enclosed parameters are optional. Parameters that are not enclosed by brackets must be specified.A|B
: indicates that the parameters separated by the vertical bars (|) are mutually exclusive. Only one of the parameters can be specified....
: indicates that the parameter preceding this symbol can be repeatedly specified.
EXTS.P.CREATE
Item | Description |
Syntax |
|
Time complexity | O(1) |
Command description | Creates a TairTS pkey. If a pkey with the same name already exists, the pkey cannot be created. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
EXTS.S.CREATE
Item | Description |
Syntax |
|
Time complexity | O(1) |
Command description | Creates an skey in a specified pkey. If the pkey does not exist, it is automatically created. If an skey with the same name already exists, the skey cannot be created. Note You can specify parameters for the skey, such as the expiration time and whether to enable compression. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
EXTS.S.ALTER
Item | Description |
Syntax |
|
Time complexity | O(1) |
Command description | Modifies the metadata of a specified skey. Only the DATA_ET time value can be modified. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
EXTS.S.ADD
Item | Description |
Syntax |
|
Time complexity | O(1) |
Command description | Inserts a data point into an skey. If the pkey or skey does not exist, the pkey or skey is automatically created. The parameters for the skey, such as the expiration time and whether to enable compression, take effect only if the skey is automatically created. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
EXTS.S.MADD
Item | Description |
Syntax |
|
Time complexity | O(n), where n indicates the number of skeys. |
Command description | Inserts a data point into multiple skeys of a pkey. If the pkey or an skey does not exist, the pkey or skey is automatically created. The parameters for an skey, such as the expiration time and whether to enable compression, take effect only if the skey is automatically created. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
EXTS.S.INCRBY
Item | Description |
Syntax |
|
Time complexity | O(1) |
Command description | Inserts a data point into an skey. If the data point that you want to insert has a positive value, the inserted value is added to the value of the last data point that exists in the skey. If the data point has a negative value, the inserted value is subtracted from the value of the last data point that exists in the skey. If the pkey or skey does not exist, the pkey or skey is automatically created. The default initial value is 0. The parameters for the skey, such as the expiration time and whether to enable compression, take effect only if the skey is automatically created. |
Parameter |
|
Output |
|
Example | Run the Sample command:
Sample output:
If the
|
EXTS.S.MINCRBY
Item | Description |
Syntax |
|
Time complexity | O(n), where n indicates the number of skeys. |
Command description | Inserts a data point into multiple skeys of a pkey. If the data point that you want to insert has a positive value, the inserted value is added to the value of the last data point that exists in each skey. If the data point has a negative value, the inserted value is subtracted from the value of the last data point that exists in each skey. If the pkey or an skey does not exist, the pkey or skey is automatically created. The default initial value is 0. The parameters for an skey, such as the expiration time and whether to enable compression, take effect only if the skey is automatically created. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
EXTS.S.DEL
Item | Description |
Syntax |
|
Time complexity | O(1) |
Command description | Deletes an skey and all data points in the skey from a pkey. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
EXTS.S.GET
Item | Description |
Syntax |
|
Time complexity | O(1) |
Command description | Queries the value of the last data point in a specified skey. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
EXTS.S.INFO
Item | Description |
Syntax |
|
Time complexity | O(1) |
Command description | Queries the metadata of a specified skey. The metadata includes the number of data points, the timestamp and value of the last data point, and the label information of the skey. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
EXTS.S.QUERYINDEX
Item | Description |
Syntax |
|
Time complexity | O(n), where n indicates the maximum number of sets involved in filter conditions. |
Command description | Queries the skeys that meet specified filter conditions in a pkey. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
EXTS.S.RANGE
Item | Description |
Syntax |
|
Time complexity | O(n), where n indicates the number of chunks to which the data points belong. |
Command description | Queries the number of data points that exist in an skey during a specified time range. The time range is a closed interval. |
Parameter |
|
Output |
|
Example | Sample command: Sample output: |
EXTS.S.MRANGE
Item | Description |
Syntax |
|
Time complexity | O(n), where n indicates the number of chunks to which the data points belong. |
Command description | Queries the number of data points that meet specified filter conditions in multiple skeys during a specified time range. The time range is a closed interval. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
EXTS.P.RANGE
Item | Description |
Syntax |
|
Time complexity | O(n), where n indicates the number of chunks to which the data points belong. |
Command description | Aggregates data points in a pkey that meet specified filter conditions. If you specify one or more skeys for aggregation, the skeys are first aggregated in the same manner as when the EXTS.S.MRANGE command is used. Then, pkeys are aggregated based on the skey aggregation results. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
EXTS.S.RAW_MODIFY
Item | Description |
Syntax |
|
Time complexity | O(1) |
Command description | Modifies the value of a data point in a specified skey. If the pkey or skey does not exist, the pkey or skey is automatically created. The parameters for the skey, such as the expiration time and whether to enable compression, take effect only if the skey is automatically created. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
EXTS.S.RAW_MMODIFY
Item | Description |
Syntax |
|
Time complexity | O(n), where n indicates the number of skeys. |
Command description | Modifies the value of a data point in multiple skeys at a time. If the pkey or an skey does not exist, the pkey or skey is automatically created. The parameters for an skey, such as the expiration time and whether to enable compression, take effect only if the skey is automatically created. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
EXTS.S.RAW_INCRBY
Item | Description |
Syntax |
|
Time complexity | O(1) |
Command description | Modifies the value of a data point in a specified skey. You can specify an increment or a decrement by which to modify the value. If the pkey or skey does not exist, the pkey or skey is automatically created. The default initial value is 0. The parameters for the skey, such as the expiration time and whether to enable compression, take effect only if the skey is automatically created. |
Parameter |
|
Output |
|
Example | Run the Sample command:
Sample output:
If the
|
EXTS.S.RAW_MINCRBY
Item | Description |
Syntax |
|
Time complexity | O(n), where n indicates the number of skeys. |
Command description | Modifies the value of a data point in multiple skeys at a time. You can specify an increment or a decrement by which to modify the values. If the pkey or an skey does not exist, the pkey or skey is automatically created. The parameters for an skey, such as the expiration time and whether to enable compression, take effect only if the skey is automatically created. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
Index filtering syntax
Skeys can be filtered by label. The following syntax is used for filter conditions.
When you specify a filter condition, you can use one or more of the following commands and you must use one of the EQ, CONTAINS, and LIST_MATCH logics.
Filter command | Description | Logic |
| The value of label L equals V. | EQ (equals) |
| The value of label L is not NULL, which indicates that the skey contains label L. | CONTAINS |
| The value of label L matches one of the values in the list, such as v1 or v2. | LIST_TMATCH |
| The value of label L does not equal V. | NOEQ (equals) |
| The value of label L is NULL, which indicates that the skey does not contain label L. | NOCONTAINS |
| The value of label L does not match any of the values in the list, such as v1 or v2. | LIST_NOTMATCH |
Aggregation syntax
In aggregate operations, data that exists in multiple time buckets is aggregated. The following aggregation types are supported:
MAX
: returns the maximum value.MIN
: returns the minimum value.AVG
: returns the average value.SUM
: returns the sum of all values.FIRST
: returns the first value.LAST
: returns the last value.RANGE
: returns the range from the minimum value to the maximum value.COUNT
: returns the number of values.STD.P
: returns the population variance.STD.S
: returns the sample variance.VAR.P
: returns the population standard deviation.VAR.S
: returns the sample standard deviation.