RedisTimeSeries: Storing Metrics and Monitoring Data Efficiently
AI generated
SET
TTL
Redis Stack / RedisTimeSeries
RedisTimeSeries: Storing Metrics Efficiently
Downsampling and retention directly in Redis

Anyone who wants to observe requests per second, response times, or cart events over time quickly ends up needing a dedicated time series database. RedisTimeSeries brings exactly this data model directly into Redis, with automatic downsampling, configurable retention policies, and the same low latency Redis already offers for other data types.

12 min read RedisTimeSeries Downsampling Retention Monitoring Redis Stack

1. Why Time Series Data Needs Its Own Data Model

Metrics such as requests per second or response times differ fundamentally from classic Redis use cases: the point is not the current value of a single key, but a continuous sequence of timestamp-value pairs that grows over hours, days, or months. Without a specialized data model, every single measurement would have to be stored as its own sorted set entry or its own key, which quickly leads to millions of entries at high measurement frequency.

RedisTimeSeries solves this by introducing its own data type for time series that is internally optimized for sequential timestamps and offers functions like downsampling, retention, and aggregation directly in the server, without the application having to implement this logic itself.

2. The Data Model: TS.CREATE and TS.ADD

A time series is created with TS.CREATE and can optionally be given labels, which later enable queries across multiple time series, similar to labels in Prometheus. New data points are added via TS.ADD with a timestamp and a value, where the timestamp can either be specified explicitly or automatically set to the current server time using the asterisk placeholder.

For high-frequency metrics, such as requests per second from multiple application servers, TS.MADD is recommended, which writes multiple data points across different time series in a single command and thereby avoids the overhead of many individual network round trips.


redis-cli TS.CREATE metric:requests:webserver1 LABELS service webserver1 type requests

redis-cli TS.ADD metric:requests:webserver1 '*' 142

redis-cli TS.MADD metric:requests:webserver1 '*' 150 metric:requests:webserver2 '*' 98

3. Downsampling Rules: Maintaining Aggregated Time Series Automatically

Raw data at second-level resolution is important for real-time dashboards, but unnecessarily detailed and memory-intensive for long-term analysis spanning months. RedisTimeSeries solves this with downsampling rules through TS.CREATERULE: a source time series is linked to a destination time series that automatically receives aggregated values over a larger time window, such as a per-minute average or an hourly maximum.

These rules run server side and fully automatically: as soon as a new value is written to the source time series, Redis updates the linked, aggregated destination series in the background. The application neither has to run its own cron job for aggregation nor iterate over historical raw data afterward.


redis-cli TS.CREATE metric:requests:1min AGGREGATION avg 60000

redis-cli TS.CREATERULE metric:requests:webserver1 metric:requests:1min AGGREGATION avg 60000

4. Retention Policies: Discarding Old Raw Data Automatically

Without a cleanup mechanism, raw data at second-level resolution would grow indefinitely and eventually exhaust available memory. RedisTimeSeries solves this through the RETENTION option on TS.CREATE, which specifies how long data points are kept in milliseconds before they are automatically removed from the time series.

In practice, teams combine a short retention window for high-resolution raw data with a long or unlimited retention window for the downsampled destination series: second-level values are kept for only a few hours, minute-level aggregates for several weeks, and hourly aggregates potentially indefinitely. This keeps memory usage under control without having to give up historical trends.


redis-cli TS.CREATE metric:requests:webserver1 RETENTION 21600000 LABELS service webserver1

redis-cli TS.CREATE metric:requests:1min RETENTION 5184000000 LABELS service webserver1 resolution 1min

5. Comparison to Prometheus and InfluxDB

Prometheus follows a pull model: the server periodically scrapes metrics from the monitored services and stores them in its own storage engine optimized for time series. RedisTimeSeries instead works on a push model, applications actively write values via TS.ADD, which is especially suited for event-driven metrics that do not fit into a fixed scrape interval, such as individual cart events.

InfluxDB, with its own query language and mature continuous queries, offers functionally more options for complex time series analysis and is usually the more economical choice for very large, long-term metric volumes, since it is designed for disk persistence rather than in-memory storage. RedisTimeSeries, in turn, scores with the low latency of Redis and the ability to run metrics right alongside already existing Redis data such as sessions or caches, without setting up an additional system.

6. Practical Example: Requests per Second and Cart Events

In a Magento shop, two different kinds of metrics map well to RedisTimeSeries: technical metrics such as requests per second per web server, written at regular intervals from a middleware hook, and business events such as completed cart abandonment events, which arrive irregularly but with high priority for real-time dashboards.

Both kinds of metrics benefit from automatic downsampling: requests per second are kept at second-level resolution for a live dashboard, but additionally aggregated into hourly averages for capacity planning. Cart events can be tracked as a simple counter series with TS.INCRBY, making it possible to spot trends such as a rising abandonment rate during a checkout deployment immediately.


redis-cli TS.INCRBY metric:cart:abandoned 1

redis-cli TS.RANGE metric:requests:1min - + AGGREGATION avg 3600000

7. Aggregation Queries with TS.RANGE and TS.MRANGE

For analysis, TS.RANGE offers a filtered query over a time range, optionally with its own aggregation function computed at query time, independent of the fixed downsampling rules configured on the series. TS.MRANGE extends this to multiple time series at once, filtered by labels, which is particularly practical with many individual web server instances, for example to combine all request metrics of a given service into a single query.

This flexible query layer makes it possible to use the same raw data both for granular single-server views and for aggregated service overviews, without having to create a dedicated downsampling rule for every use case. For standard aggregations that are needed permanently, fixed rules via TS.CREATERULE still make sense, because they shift the computational cost from query time to write time.


redis-cli TS.MRANGE - + FILTER service=webserver1 AGGREGATION avg 60000

8. Integration with Alerting and Monitoring Stacks

In most setups RedisTimeSeries does not replace a full monitoring stack, but it works well as a fast, already available data source for event-driven business metrics. Through a Prometheus exporter or custom query scripts, RedisTimeSeries values can periodically feed existing alerting systems without duplicating the actual metric collection.

For simple threshold alerts, a cron job that queries the last few minutes via TS.RANGE and triggers a notification when a limit is exceeded is often already enough. For more complex alerting rules with multi-stage conditions and escalation paths, however, a dedicated alerting tool like Alertmanager remains the more robust foundation.

9. Operational Limits in Production Use

The in-memory nature of Redis also applies to RedisTimeSeries: without consistent retention policies, memory usage grows uncontrollably, and a full Redis server affects not just metrics but also all other use cases, such as cache or session storage, that might share the same instance. For production setups, a dedicated RedisTimeSeries instance, separate from the cache backend, is therefore recommended.

Failure resilience also deserves a closer look: metric data is naturally less critical than session data, and a brief data loss during a failover is usually tolerable. Anyone who needs long-term, immutable historical data for compliance purposes should treat RedisTimeSeries more as a fast operational buffer and leave long-term archiving to a classic time series database or a data warehouse.

Aspect RedisTimeSeries Prometheus/InfluxDB
Write model Push, application actively writes via TS.ADD Prometheus: pull via scrape interval
Downsampling Server-side rules via TS.CREATERULE Recording rules or continuous queries
Persistence In-memory with RDB/AOF snapshot Storage engine optimized for disk persistence
Write latency Very low, the same Redis latency as other types Higher due to scrape interval or batch writes
Long-term storage of large volumes Limited by available memory More economical for very large historical volumes
Dashboard ecosystem Grafana plugin available, smaller ecosystem Very broad ecosystem, Grafana as a de facto standard

Mironsoft

Cache layer setup and Magento Redis integration

Magento cache that isn't quite working or is misconfigured?

We set up Redis as a cache and session backend for Magento cleanly, tune memory usage and eviction strategies, and make sure full page cache and session storage work together reliably.

Redis Setup

Configure the cache, session, and FPC backend production-ready for Magento.

Memory Tuning

Match memory usage and eviction policies to the shop's actual load.

High Availability Setup

Set up Redis Sentinel or Cluster for resilient Magento environments.

10. Summary

RedisTimeSeries: The Essentials at a Glance

Core Idea

Time series data type with downsampling and retention directly in Redis

Core Commands

TS.CREATE, TS.ADD, TS.CREATERULE, TS.RANGE, TS.MRANGE

Typical Use

Event-driven business metrics and latency-critical monitoring

Limits

In-memory storage limits, not a replacement for long-term archiving

11. FAQ: RedisTimeSeries: The Essentials at a Glance

1Is RedisTimeSeries a replacement for Prometheus?
Not generally. It is well suited for event-driven metrics with low latency, while Prometheus usually remains the better fit for broad infrastructure monitoring with its established scrape model and large ecosystem.
2How long is raw data kept by default?
Without an explicit RETENTION setting on TS.CREATE, data points are stored indefinitely, which quickly leads to significant memory usage at high write frequency. A retention policy should therefore always be set deliberately.
3What happens to a downsampling rule when the source time series is deleted?
The linked destination series remains with its already aggregated values but no longer receives new updates, since the rule was bound to a source that no longer exists.
4Can RedisTimeSeries compute several aggregation functions for the same source at once?
Yes, several rules with different destination series and aggregation functions can be applied to the same source time series, for example average and maximum in separate destination series simultaneously.
5How are labels used for queries across multiple time series?
Labels are assigned as key-value pairs on TS.CREATE and can be used as a filter expression on TS.MRANGE, for example to query all time series of a given service regardless of the exact instance.
6Is RedisTimeSeries part of the standard Redis server?
No, like RedisJSON and RediSearch, RedisTimeSeries is a separate module that must be provided through Redis Stack or Redis Enterprise.
7How high is the memory overhead per data point?
RedisTimeSeries internally uses a compressed storage structure similar to the Gorilla compression scheme, which keeps memory usage per data point well below that of a naive sorted set entry, though not at zero.
8Can alerts be triggered directly from RedisTimeSeries?
RedisTimeSeries itself does not trigger alerts, but it provides the data basis via TS.RANGE for external alerting scripts or systems that check thresholds.
9How does TS.INCRBY compare to a normal counter?
TS.INCRBY atomically increases the last value of the time series and simultaneously creates a new timestamp-value entry, combining the function of a counter with that of a time series in a single command.
10Is RedisTimeSeries suited for compliance-relevant long-term archiving?
Rather not as the sole solution. For data that must be kept immutable over years, a classic time series database or a data warehouse with appropriate guarantees is the more robust foundation.