อนุกรมเวลาด้วย RedisTimeSeries
จัดเก็บ ลดความละเอียด และสืบค้นตัวชี้วัดอย่างมีประสิทธิภาพด้วยโมดูล RedisTimeSeries โดยใช้การเก็บรักษา การบีบอัด และการรวมข้อมูล
อนุกรมเวลาด้วย RedisTimeSeries เป็นบทเรียน Redis Caching & Messaging (Pub/Sub, Streams) ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน 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 kitchenAdding 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.0Auto-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 kitchenQuerying 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 1716903600000Aggregating 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 60000Downsampling 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 3600000Querying 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=kitchenRetention 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 604800000Inspecting a Series
TS.INFO reports sample count, memory, retention, labels, and any compaction rules attached to a series.
TS.INFO sensor:tempWhere 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.
คำถามที่พบบ่อย
บทเรียน “อนุกรมเวลาด้วย RedisTimeSeries” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “อนุกรมเวลาด้วย RedisTimeSeries” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Redis Caching & Messaging (Pub/Sub, Streams) ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Redis Caching & Messaging (Pub/Sub, Streams) มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “อนุกรมเวลาด้วย RedisTimeSeries”
จัดเก็บ ลดความละเอียด และสืบค้นตัวชี้วัดอย่างมีประสิทธิภาพด้วยโมดูล RedisTimeSeries โดยใช้การเก็บรักษา การบีบอัด และการรวมข้อมูล คุณปฏิบัติ Redis Caching & Messaging (Pub/Sub, Streams) ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Redis Caching & Messaging (Pub/Sub, Streams) หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Redis Caching & Messaging (Pub/Sub, Streams) บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน
บทเรียน “อนุกรมเวลาด้วย RedisTimeSeries” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Redis Caching & Messaging (Pub/Sub, Streams) นี้ได้ไหม
ได้ บทเรียน Redis Caching & Messaging (Pub/Sub, Streams) ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- ภาพรวมโมดูลของ Redis
- RediSearch สำหรับการค้นหาข้อความเต็มรูปแบบ
- พื้นฐาน RedisJSON และ RedisGraph
- อนุกรมเวลาด้วย RedisTimeSeries