Advertisement
Beginner Redis, RedisTimeSeries

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

Short answer

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.

Save Redis mock interview
Advertisement
AModel answer
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.
Example

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.
Likely 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?
Related topics