RedisTimeSeries

7 questions found

What is RedisTimeSeries, and what kind of data is it specifically designed to handle?

Beginner
RedisTimeSeries is a module specifically designed for efficiently storing and querying time stamped data, such as sensor readings, application metrics, or stock prices, providing specialized commands for adding data points, querying ranges of time, and automatically aggregating or downsampling data over time.
TS.CREATE temperature_sensor1
TS.ADD temperature_sensor1 '*' 22.5
Real-world example An industrial monitoring system uses RedisTimeSeries to efficiently store temperature readings from thousands of sensors, taking advantage of its specialized time based querying and aggregation capabilities.

Common follow-ups: How is RedisTimeSeries different from just using a sorted set with timestamps as scores?;What happens if you add a data point with a timestamp that is out of order?

Redis Modules Overview;Sets & Sorted Sets in Redis

How do you add a new data point to a Redis time series, and how do you query a range of recent data?

Beginner
You use TS.ADD to add a new value with either a specific timestamp or an asterisk to automatically use the current time, and TS.RANGE to retrieve all data points falling within a specified time range, letting you easily query for something like all readings from the last hour.
TS.ADD temperature_sensor1 '*' 23.1
TS.RANGE temperature_sensor1 - +
Real-world example A weather monitoring dashboard adds new temperature readings as they arrive and queries the full range of recent readings using TS.RANGE to display a chart of temperature over time.

Common follow-ups: What do the minus and plus symbols represent in a TS.RANGE query?;Can you query a time series using a specific start and end timestamp instead?

Data Types;Sets & Sorted Sets in Redis

How do you configure automatic downsampling in RedisTimeSeries, where detailed recent data is aggregated into coarser summaries over time?

Intermediate
You create a compaction rule using TS.CREATERULE, specifying a source time series, a destination time series, an aggregation type like average or maximum, and a bucket duration, which automatically creates aggregated data points in the destination series as new raw data arrives in the source, letting you keep detailed recent data while automatically summarizing older data into less granular form.
TS.CREATE temperature_hourly_avg
TS.CREATERULE temperature_sensor1 temperature_hourly_avg AGGREGATION avg 3600000
Real-world example A sensor monitoring system keeps detailed second by second readings for the past day, while automatically maintaining an hourly average time series for long term historical trend analysis, without needing to manually calculate and store these aggregates.

Common follow-ups: What aggregation types are available besides average, such as sum or maximum?;Does downsampling automatically delete the original detailed data?

RedisTimeSeries;Redis Modules Overview

How do you configure a retention period for a Redis time series so old data is automatically removed after a certain amount of time?

Intermediate
You set a retention period, specified in milliseconds, either when creating the time series or by altering it afterward, and Redis automatically removes any data points older than that configured retention window, keeping the time series from growing indefinitely while retaining only the recent history your application actually needs.
TS.CREATE sensor_data RETENTION 86400000
-- Keeps only the last 24 hours of raw data
Real-world example A high frequency sensor monitoring system configures a twenty four hour retention period for its raw data time series, automatically discarding older detailed readings while relying on downsampled aggregates for longer term historical analysis.

Common follow-ups: How do you change the retention period on an already existing time series?;What happens to data that has already exceeded the configured retention period?

Expiration & Eviction;Redis Modules Overview

How would you design a monitoring system architecture using RedisTimeSeries that efficiently handles both high frequency raw data ingestion and long term historical trend analysis?

Advanced
You would configure a short retention period for high frequency raw data optimized for immediate alerting and detailed recent analysis, set up multiple compaction rules creating progressively coarser aggregated time series such as hourly, daily, and monthly summaries, and configure appropriately longer retention periods for each of those aggregated series based on how far back you actually need historical trend visibility.
TS.CREATE raw_metrics RETENTION 3600000
TS.CREATE hourly_metrics RETENTION 604800000
TS.CREATERULE raw_metrics hourly_metrics AGGREGATION avg 3600000
Real-world example A large scale infrastructure monitoring platform maintains raw metrics for just one hour for immediate alerting, hourly aggregates for a week of detailed trend analysis, and monthly aggregates retained indefinitely for long term capacity planning, all automatically maintained through RedisTimeSeries compaction rules.

Common follow-ups: How many levels of downsampling are typically reasonable for a monitoring system?;What is the storage tradeoff between keeping more levels of aggregation versus fewer?

Redis Memory Optimization;Redis Modules Overview

How does RedisTimeSeries handle labels and how can you use them to query across multiple related time series at once?

Advanced
You can attach labels, which are key value metadata pairs, to a time series when creating it, and use TS.MRANGE with a label based filter expression to query across all time series matching those labels simultaneously, which is especially useful when you have many similar time series, such as one per server or sensor, and need to analyze them together.
TS.CREATE cpu_usage:server1 LABELS region 'us-east' role 'web'
TS.MRANGE - + FILTER region=us-east
Real-world example A cloud infrastructure monitoring system labels each server's CPU usage time series with its region and role, letting an operator query the combined CPU usage trend across every web server in a specific region with a single command.

Common follow-ups: How many labels can reasonably be attached to a single time series?;What is the performance difference between querying a single series versus using MRANGE across many labeled series?

Redis Modules Overview;Data Types

What aggregation functions are available when querying a range of data from a Redis time series, and how do you apply one during a query?

Intermediate
RedisTimeSeries supports aggregation functions including avg, sum, min, max, count, and several others, which you apply to a TS.RANGE query using the AGGREGATION clause along with a specified time bucket duration, letting you retrieve summarized data, such as the average value per hour, directly from a query rather than needing to calculate it yourself afterward.
TS.RANGE temperature_sensor1 - + AGGREGATION avg 3600000
Real-world example A dashboard displaying a chart of average hourly temperature over the past week retrieves this exact summarized data directly from a single TS.RANGE query using the avg aggregation, without needing any additional calculation in the application code.

Common follow-ups: What is the difference between applying aggregation during a query versus using a compaction rule?;How do you choose an appropriate bucket duration for a specific chart or report?

RedisTimeSeries;Data Types