Redis Caching & Messaging (Pub/Sub, Streams) · 课时

使用 RedisTimeSeries 处理时间序列

使用 RedisTimeSeries 模块存储、降采样和高效查询指标,并配置保留、压缩和聚合

第 4 / 4 课13 个步骤

使用 RedisTimeSeries 处理时间序列 是 CoddyKit 上的免费 Redis Caching & Messaging (Pub/Sub, Streams) 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Redis Caching & Messaging (Pub/Sub, Streams) 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Redis Caching & Messaging (Pub/Sub, Streams) 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

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.

免费开始

用 AI 导师学习 Redis Caching & Messaging (Pub/Sub, Streams) — 免费

在浏览器中编写并运行真实代码,获得全天候 AI 导师的即时帮助,并在网页或应用中继续学习。

课程
12
课程
48

常见问题解答

「使用 RedisTimeSeries 处理时间序列」课时是免费的吗?

是的 — 「使用 RedisTimeSeries 处理时间序列」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Redis Caching & Messaging (Pub/Sub, Streams) 课程的其余内容,请升级到 CoddyKit PRO。 Redis Caching & Messaging (Pub/Sub, Streams) 课程共包含 4 节课。

「使用 RedisTimeSeries 处理时间序列」这节课中我会学到什么?

使用 RedisTimeSeries 模块存储、降采样和高效查询指标,并配置保留、压缩和聚合 你通过在浏览器中直接运行的动手代码来练习 Redis Caching & Messaging (Pub/Sub, Streams),全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Redis Caching & Messaging (Pub/Sub, Streams) 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Redis Caching & Messaging (Pub/Sub, Streams) 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。

「使用 RedisTimeSeries 处理时间序列」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Redis Caching & Messaging (Pub/Sub, Streams) 课中编写并运行代码吗?

能。每节 Redis Caching & Messaging (Pub/Sub, Streams) 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. Redis 模块概览
  2. 使用 RediSearch 实现全文搜索
  3. RedisJSON 与 RedisGraph 基础
  4. 使用 RedisTimeSeries 处理时间序列
← 返回 Redis Caching & Messaging (Pub/Sub, Streams)