This content originally appeared on DEV Community and was authored by Rijul Rajesh
When working on applications like IoT monitoring, financial analytics, or server metrics tracking, one common data pattern keeps showing up: time-series data. This is data that’s collected over time, usually with a timestamp attached to every entry—like temperature readings every second, or website traffic logged minute by minute.
While Redis is often associated with caching and in-memory key-value storage, it’s also incredibly powerful when extended with modules. One such module, tailor-made for handling time-series data, is RedisTimeSeries.
What Is RedisTimeSeries?
RedisTimeSeries is a Redis module developed to efficiently store, manage, and query time-series data. It provides specialized data structures and commands that are optimized for time-stamped entries.
With RedisTimeSeries, you can:
- Ingest high-frequency data (like sensor readings or metrics)
- Set retention policies to automatically delete old data
- Perform real-time aggregations
- Query data over custom time intervals
- Downsample data using compaction rules
This makes RedisTimeSeries ideal for systems where you care about performance, flexibility, and working with data in real-time.
Why Use RedisTimeSeries Instead of Just Redis?
Yes, Redis itself can store time-series data—people often use sorted sets or lists with timestamps. But managing all the logic manually gets messy quickly, especially when you need to:
- Keep data within a specific time window
- Perform statistical calculations (like average or max over time)
- Query efficiently across time ranges
RedisTimeSeries abstracts all of that. It gives you:
- Purpose-built commands like
TS.ADD
,TS.MRANGE
,TS.CREATE
,TS.RANGE
- Native support for retention and aggregation
- Simpler and faster data access patterns
You can focus on your application logic while RedisTimeSeries handles the time-series plumbing.
Key Features at a Glance
1. Efficient Data Ingestion
Add time-stamped data points with a simple command:
TS.ADD temperature:room1 * 26.5
Here, *
tells Redis to use the current server time.
2. Retention Policies
Want to keep only the last 24 hours of data? You can configure that:
TS.CREATE temperature:room1 RETENTION 86400000
Now, old data automatically expires after 24 hours (in milliseconds).
3. Downsampling and Aggregation
You can automatically downsample your data (e.g., average every 5 minutes) into another series:
TS.CREATERULE temperature:room1 avg_temp_5min AGGREGATION avg 300000
4. Range Queries
Want to see how a value changed over a day?
TS.RANGE temperature:room1 - + AGGREGATION avg 60000
This shows the average temperature for every minute (60000
ms) between the earliest (-
) and latest (+
) timestamps.
Real-World Use Cases
IoT and Smart Devices
Monitor sensors that report values frequently—like temperature, humidity, or motion detection—and run real-time dashboards or alerts.
DevOps and Monitoring
Track metrics like CPU usage, memory, or response time, and query trends over time to detect anomalies or generate visualizations.
Finance and Trading
Store and analyze stock prices, cryptocurrency values, or transactions with millisecond precision.
Getting Started with RedisTimeSeries
You can try RedisTimeSeries locally using Docker:
docker run -p 6379:6379 redislabs/redistimeseries
Then connect with a Redis CLI:
redis-cli
And you’re good to start experimenting with time-series commands.
Wrapping up
RedisTimeSeries is a powerful tool when your application needs to deal with timestamped data efficiently. Whether you’re building a real-time monitoring system or tracking user activity, this module offers a clean, high-performance way to handle time-series data directly in Redis.
If you’re a software developer who enjoys exploring different technologies and techniques like this one, check out LiveAPI. It’s a super-convenient tool that lets you generate interactive API docs instantly.
LiveAPI helps you discover, understand and use APIs in large tech infrastructures with ease!
So, if you’re working with a codebase that lacks documentation, just use LiveAPI to generate it and save time!
You can instantly try it out here!
This content originally appeared on DEV Community and was authored by Rijul Rajesh