Updated February 17, 2023
Introduction to RedisTimeSeries
RedisTimeSeries is a redis module that was used to add the data structure name as time series into the redis. It simplifies the use of Redis for time series use cases such as stock prices, IoT, and telemetry. By using it we can ingest the query in millions of events and samples at redis speed. The RedisTimeSeries is used in advanced tooling.
- We can use RedisTimeSeries advanced tools such as aggregation and down sampling to ensure a small memory footprint without affecting performance.
- We are using the time series module in redis for adding the module or data structure into our code.
What is RedisTimeSeries?
We are using multiple queries for monitoring and visualization of built-in connections. It is a more efficient way for storing data of time series into the redis. The retention rule will query the multi-key if possible by using simple redis commands.
It will work well with the redis gears and redis API which were used to enable advanced use cases such as detection in anomaly and predictive maintenance. It will rapidly integrate with the tools like grafana, data migration, and visualization. It will automatically execute the retention rules and downsampling by using double data compression for storing datasets of large time series.
How to Install RedisTimeSeries?
We are downloading the repository of RedisTimeSeries by using git.
1. In the below example we can see that we are downloading the repository of RedisTimeSeries by using git as follows. We are cloning the RedisTimeSeries repository.
# git clone --recursive ….git
2. After cloning the directory now in this step, we are changing the directory of the RedisTimeSeries setup.
# cd RedisTimeSeries/
3. After changing the directory, now in this step we are using the make setup command to set up the redis time change as follows.
# make setup
4. After setting up the RedisTimeSeries, now we are starting the redis server by using the below command.
5. After starting the service, now we are checking the service and RedisTimeSeries installation while login in the redis server by using the redis cli command.
The data is modeled in RedisTimeSeries according to the application model. It is dependent on the power of redis, as well as redis json and redis search. While storing data on the cloud and local machine, all redis commands are identical.
The following example shows how we can store data using RedisTimeSeries:
In the below example, we are creating the rb file to execute the RedisTimeSeries data store as follows.
time_series = Redis::TimeSeries.new('RedisTimeSeries')
time_series.range (Time.now.to_i - 200)..Time.now.to_i * 1000
We create the time series as a variable and assign it throughout the code. In the following example, we are creating a time series that represents the temperature for the specified measurement. Following the creation of the temperature measurement, we query the data for the specified time range for the aggregation rule, as shown below. We create the rb file for the same as follows.
time_series.CREATE temp:3:11 RETENTION 30 LABELS s_id 4 a_id 16
time_series.ADD temp:2:13 181 10
time_series.ADD temp:2:13 154 22
time_series.RANGE temp:2:13 150 190 AGGREGATION avg 4
The RedisTimeSeries model is used to implement the timeseries data by using a rich set of commands. It will maintain the linked list which was used to core that specified lightweight node. Every node from the linked list will consist of two corresponding arrays with a size of 128 bits. The single array is used to store the timestamps and the other array is used to store the sample values. The redis time stamp and its value are called a sample.
Below figure shows how the RedisTimeSeries model will work as follows:
From the above model, we can see that first, we are creating new time series. In the below example, we are creating the time series of redis_temp. After creating the time series, we need to add the new sample to the time series. We can add any sample to the time series. After adding the sample, we need to range the query across the time series which we have defined.
Below example shows how the RedisTimeSeries module will work as follows:
t_ser.CREATE redis_temp:3:11 RETENTION 15 LABELS s_id 2 a_id 8
t_ser.ADD redis_temp:1:7 181 10
t_ser.ADD redis_temp:1:7 154 22
t_ser.RANGE redis_temp:1:7 150 190 AGGREGATION avg 2
RedisTimeSeries contains multiple features.
- It is used to read the low latency and used in a high-volume insertion of data.
- We can query into the redis database as per start and end time by using it.
- We can use the aggregated query like avg, min, sum, max Var.P, Var.S, and many more. This query is used for a specified time of bucket.
- While using it we can configure the retention period which was maximum.
- We can use it to perform down sampling. We are using down sampling for aggregated time series.
- We can use the secondary indexes for entries that contain the time series. Every time series contain the labels.
- By using the redis time scale we can ingest the data fastly by using the infinite scale onto the dataset of time series.
- By using it we can automatically execute the retention rules and the down sampling.
- We can easily detect the anomaly that occurred in our program by using it.
- We can collect the telemetry type of data from multiple devices which was located remotely by using RedisTimeSeries.
- Application monitory is very while using time series in redis. We can gain deep insights of the application.
Given below are the FAQs mentioned:
Q1. What is the use of RedisTimeSeries?
Answer: It is nothing but the module which is used to load the data structure of the time series.
Q2. How can we use RedisTimeSeries with redis-cli?
Answer: To use it with redis cli, first load the RedisTimeSeries module, then connect to the Redis server using redis cli. After connecting to redis-cli, we can run the command.
Q3. Which configuration parameter we are using at the time of loading the RedisTimeSeries module?
Answer: We are using the configuration parameter name as num threads, compaction policy, retention policy, duplicate policy, and chunk type parameter while using it.
RedisTimeSeries will work well with Redis Gears and the Redis API, which were used to enable advanced use cases such as anomaly detection and predictive maintenance. It simplifies the use of Redis for time series use cases such as stock prices, IoT, and telemetry.
This is a guide to RedisTimeSeries. Here we discuss the introduction, how to install redisTimeSeries? datastore, model, and features. You may also have a look at the following articles to learn more –