0Pricing
Redis Caching & Messaging (Pub/Sub, Streams) · Lesson

Time Series with RedisTimeSeries

Store, downsample, and query metrics efficiently using the RedisTimeSeries module with retention, compaction, and aggregation.

Time Series with RedisTimeSeries is a free Redis Caching & Messaging (Pub/Sub, Streams) lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Redis Caching & Messaging (Pub/Sub, Streams) learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why a Time Series Module?

Storing metrics (CPU, temperature, request counts) as plain keys wastes memory and makes range queries awkward. RedisTimeSeries is a module purpose-built for timestamped numeric data, with compression, retention, and downsampling.

Creating a Series

TS.CREATE makes a new series. You can set retention (how long to keep samples) and labels for filtering.

TS.CREATE sensor:temp RETENTION 86400000 LABELS room kitchen

Adding Samples

TS.ADD appends a timestamped value. Use * for the current server time, or supply an explicit millisecond timestamp.

TS.ADD sensor:temp * 21.5
TS.ADD sensor:temp 1716900000000 22.0

Auto-Creating on Add

If a series does not exist, TS.ADD can create it on the fly, optionally with retention and labels, which is handy for high-cardinality ingest.

TS.ADD sensor:hum * 55 RETENTION 3600000 LABELS room kitchen

Querying a Range

TS.RANGE returns samples between two timestamps. Use - and + for the minimum and maximum bounds.

TS.RANGE sensor:temp - +
TS.RANGE sensor:temp 1716900000000 1716903600000

Aggregating Buckets

Add AGGREGATION to bucket and summarize samples, for example averaging into 60-second windows.

  • Functions: avg, min, max, sum, count
TS.RANGE sensor:temp - + AGGREGATION avg 60000

Downsampling with Rules

A compaction rule automatically writes aggregated values from a source series into a lower-resolution destination, keeping long-term data cheap.

TS.CREATE sensor:temp:hourly
TS.CREATERULE sensor:temp sensor:temp:hourly AGGREGATION avg 3600000

Querying Across Series

TS.MRANGE queries multiple series at once, filtered by labels, ideal for dashboards showing all sensors in a room.

TS.MRANGE - + FILTER room=kitchen

Retention in Action

The RETENTION setting (in milliseconds) auto-expires old samples. Combine short retention on raw series with long retention on downsampled series for a tiered storage strategy.

TS.ALTER sensor:temp RETENTION 604800000

Inspecting a Series

TS.INFO reports sample count, memory, retention, labels, and any compaction rules attached to a series.

TS.INFO sensor:temp

Where It Fits

RedisTimeSeries shines for monitoring, IoT telemetry, and real-time analytics where you need fast appends, range queries, and automatic downsampling without a separate time-series database.

Quick Check

Test your understanding of RedisTimeSeries.

Recap

You used RedisTimeSeries to create series with retention and labels, add samples, query ranges with aggregation, downsample via compaction rules, query many series with TS.MRANGE, and inspect them with TS.INFO. It is a compact way to handle metrics and telemetry inside Redis.

Frequently asked questions

Is the “Time Series with RedisTimeSeries” lesson free?

Yes — the full text of “Time Series with RedisTimeSeries” is free to read here on the web, and the Redis Caching & Messaging (Pub/Sub, Streams) course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Redis Caching & Messaging (Pub/Sub, Streams) course, upgrade to CoddyKit PRO.

What will I learn in “Time Series with RedisTimeSeries”?

Store, downsample, and query metrics efficiently using the RedisTimeSeries module with retention, compaction, and aggregation. You practise Redis Caching & Messaging (Pub/Sub, Streams) with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Redis Caching & Messaging (Pub/Sub, Streams)?

No prior experience is required. Redis Caching & Messaging (Pub/Sub, Streams) on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Time Series with RedisTimeSeries” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Redis Caching & Messaging (Pub/Sub, Streams) lesson?

Yes. Every Redis Caching & Messaging (Pub/Sub, Streams) lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Overview of Redis Modules
  2. RediSearch for Full-Text Search
  3. RedisJSON & RedisGraph Basics
  4. Time Series with RedisTimeSeries
← Back to Redis Caching & Messaging (Pub/Sub, Streams)