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?
Short answer
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…
Advertisement
AModel answer
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.
Example
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.
Likely 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?
Related topics