วันนี้ เรายินดีประกาศ General Availability ของ RedisTimeSeries 1.6 บล็อกโพสต์นี้รายละเอียด Major New Features ที่พร้อมใช้งานแล้ว
About RedisTimeSeries
RedisTimeSeries เป็น High-performance, Memory-first Time-series Data Structure สำหรับ Redis RedisTimeSeries รองรับ Time Series Multi-tenancy (สามารถ Hold Many Time Series Simultaneously) และสามารถ Serve Multiple Clients Accessing These Time Series Simultaneously ตอนนี้พร้อมใช้งานเป็นส่วนหนึ่งของ Redis Stack ด้วย
Major New Features in RedisTimeSeries 1.6
- Enhanced Querying Capabilities
- Cross-time Series Aggregations
- Filtering Results by Timestamp or Sample Value
- Selecting Which Labels to Retrieve
- Aligning Aggregation Buckets
- Deleting Samples
- Improved Performance
- Keyspace Notifications
- Redis Enterprise Support for Redis on Flash
Enhanced Querying Capabilities
Cross-time Series Aggregations
ก่อน Version 1.6 มีเพียงหนึ่งประเภทของ Aggregation:
- For a Single Time Series – Aggregating the Samples over Equidurational Timeframes
ตั้งแต่ Version 1.6 สองประเภท Aggregation ใหม่เป็นไปได้:
- For Multiple Time Series – Aggregating Samples with Equal Timestamps over the Set of Time Series
- For Multiple Time Series – First, Aggregate Each Time Series over Equidurational Timeframes, Then for Each Timeframe Aggregate the Results over the Set of Time Series
มาสาธิตประเภท Aggregation ใหม่แรก เริ่มสร้าง Two Stocks และเพิ่ม Prices ที่ 3 Timestamps ต่างกัน:
TS.CREATE stock:A LABELS type stock name A TS.CREATE stock:B LABELS type stock name B TS.MADD stock:A 1000 100 stock:A 1010 110 stock:A 1020 120 TS.MADD stock:B 1000 120 stock:B 1010 110 stock:B 1020 100
ตอนนี้เราสามารถ Retrieve Maximal Stock Price per Timestamp:
redis:6379> TS.MRANGE - + WITHLABELS FILTER type=stock GROUPBY type REDUCE max
1) 1) "type=stock" 2) 1) 1) "type" 2) "stock" 2) 1) "__reducer__" 2) "max" 3) 1) "__source__" 2) "stock:A,stock:B" 3) 1) 1) (integer) 1000 2) 120 2) 1) (integer) 1010 2) 110 3) 1) (integer) 1020 2) 120 |
FILTER type=stockClause ทำให้เราเหลือเพียง Single Time Series Representing Stock Prices
GROUPBY type REDUCE maxClause แยก Time Series เป็น Groups with Identical Type Values และแล้วสำหรับแต่ละ Timestamp Aggregate All Series that Share the Same Type Value Using the Max Aggregator
FILTER label=valueSupported by TS.MRANGE and TS.MREVRANGE Additional Filtering Clauses Supported as Well (See Documentation)
ต่อไป เราจะสาธิตประเภท Aggregation ใหม่ที่สอง:
ก่อน สร้าง Two Stocks และเพิ่ม Prices ที่ 9 Different Timestamps
TS.CREATE stock:A LABELS type stock name A TS.CREATE stock:B LABELS type stock name B TS.MADD stock:A 1000 100 stock:A 1010 110 stock:A 1020 120 TS.MADD stock:B 1000 120 stock:B 1010 110 stock:B 1020 100 TS.MADD stock:A 2000 200 stock:A 2010 210 stock:A 2020 220 TS.MADD stock:B 2000 220 stock:B 2010 210 stock:B 2020 200 TS.MADD stock:A 3000 300 stock:A 3010 310 stock:A 3020 320 TS.MADD stock:B 3000 320 stock:B 3010 310 stock:B 3020 300
ตอนนี้ สำหรับแต่ละ Stock เราจะ Calculate Average Stock Price per 1000 Millisecond Time Frame และจากนั้น Retrieve Stock with the Maximal Average for that Timeframe:
redis:6379> TS.MRANGE - + WITHLABELS AGGREGATION avg 1000 FILTER type=stock GROUPBY type REDUCE max
1) 1) "type=stock" 2) 1) 1) "type" 2) "stock" 2) 1) "__reducer__" 2) "max" 3) 1) "__source__" 2) "stock:A,stock:B" 3) 1) 1) (integer) 1000 2) 110 2) 1) (integer) 2000 2) 210 3) 1) (integer) 3000 2) 310 |
GROUPBY label REDUCE reducerSupported by TS.MRANGE and TS.MREVRANGE Reducer Can Be Sum, Min, or Max
Filtering Results by Timestamp or Sample Value
เมื่อใช้ TS.RANGE, TS.REVRANGE, TS.MRANGE, และ TS.MREVRANGE คุณไม่ได้ต้องการ Retrieve หรือ Aggregate All Samples เสมอ
Using
[FILTER_BY_TS ts...]You Can Filter the Sample by a List of Specific Timestamps
Using
[FILTER_BY_VALUE min max]You Can Filter the Sample by Minimal and Maximal Values
Consider, for Example, a Sampled Metric Where the Normal Values Are Between -100 and 100 but the Value 9999 Is Used as an Indication of Bad Measurement
TS.CREATE temp:TLV LABELS type temp location TLV TS.MADD temp:TLV 1000 30 temp:TLV 1010 35 temp:TLV 1020 9999 temp:TLV 1030 40
Now, Let's Retrieve All Values, Ignore Out-of-range Values:
TS.RANGE temp:TLV - + FILTER_BY_VALUE -100 100
Let's Also Retrieve the Average Value, Ignore Out-of-range Values:
TS.RANGE temp:TLV - + FILTER_BY_VALUE -100 100 AGGREGATION avg 1000
Selecting Which Labels to Retrieve
เมื่อใช้ TS.MRANGE, TS.MREVRANGE, และ TS.MGET เราไม่ได้ต้องการ Values of All Labels Associated with the Matching Time Series เสมอแต่ Only the Values of Selected Labels
SELECTED_LABELSAllows Selecting Which Labels to Retrieve Given the Following Time Series and Data:
TS.CREATE temp:TLV LABELS type temp location TLV TS.MADD temp:TLV 1000 30 temp:TLV 1010 35 temp:TLV 1020 9999 temp:TLV 1030 40
To Get All the Labels Associated with Matched Time Series We'll Use
WITHLABELS:
redis:6379> TS.MGET WITHLABELS FILTER type=temp
1) 1) "temp:TLV" 2) 1) 1) "type" 2) "temp" 2) 1) "location" 2) "TLV" 3) 1) (integer) 1030 2) 40 |
But Suppose We Want Only the Location We Can Use
SELECTED_LABELS:
redis:6379> TS.MGET SELECTED_LABELS location FILTER type=temp
1) 1) "temp:TLV" 2) 1) 1) "location" 2) "TLV" 3) 1) (integer) 1030 2) 40 |
Aligning Aggregation Buckets
Suppose We Want to Receive the Average Daily Temperature but Our 'Day' Starts at 06:00 In This Case We Would Like to ALIGN the Intervals to 06:00 to 05:59 Instead of to 00:00 to 23:59
When Using TS.RANGE, TS.REVRANGE, TS.MRANGE, and TS.MREVRANGE It Is Now Possible to Align the Aggregation Buckets with the Requested Start, End, or Specific Timestamp – Using
ALIGN
To Demonstrate Alignment Let's Add the Following Data:
TS.CREATE stock:A LABELS type stock name A TS.MADD stock:A 1000 100 stock:A 1010 110 stock:A 1020 120 TS.MADD stock:A 1030 200 stock:A 1040 210 stock:A 1050 220 TS.MADD stock:A 1060 300 stock:A 1070 310 stock:A 1080 320
Next, We'll Aggregate Without Using
ALIGN(Which Means Default Alignment: 0)
redis:6379> TS.RANGE stock:A - + AGGREGATION min 20
1) 1) (integer) 1000 2) 100 2) 1) (integer) 1020 2) 120 3) 1) (integer) 1040 2) 210 4) 1) (integer) 1060 2) 300 5) 1) (integer) 1080 2) 320 |
And Now with
ALIGN:
redis:6379> TS.RANGE stock:A – + ALIGN 10 AGGREGATION min 20
1) 1) (integer) 990 2) 100 2) 1) (integer) 1010 2) 110 3) 1) (integer) 1030 2) 200 4) 1) (integer) 1050 2) 220 5) 1) (integer) 1070 2) 310 |
Setting
ALIGNto 10 Means that a Bucket Should Start at Time 10 and All the Buckets (Each with a 20 Milliseconds Duration) Are Aligned Accordingly
When the Start Timestamp for the Range Query Is Explicitly Stated (Not '-') It Is Also Possible to Set ALIGN to that Time by Setting Align to '-' or to '
start'.
redis:6379> TS.RANGE stock:A 5 + ALIGN – AGGREGATION min 20
1) 1) (integer) 985 2) 100 2) 1) (integer) 1005 2) 110 3) 1) (integer) 1025 2) 200 4) 1) (integer) 1045 2) 220 5) 1) (integer) 1065 2) 310 |
Similarly When the End Timestamp for the Range Query Is Explicitly Stated (Not '+') It Is Also Possible to Set
ALIGNto that Time by Setting Align to '+' or to 'end'
Deleting Samples
TS.DEL Allows Deleting Samples in a Given Time Series Within Two Timestamps
For Example
TS.DEL stock:A 1020 1050Will Delete All Samples with Timestamps Between 1020 and 1050 (Inclusive) The Returned Value Is the Number of Samples Deleted
Improved Performance
Many Optimizations Were Implemented and Most Queries Would Now Execute Much Faster Compared to RedisTimeSeries 1.4
The Following Table Details the Number of Queries per Second Achievable on a Single Node for TSBS Queries (Which We Described Here) The Table Lists Only the Subset of the TSBS Queries that Were Supported in Version 1.4
| Query type | 1.4 queries/sec | v1.6 queries/sec | % change (higher-better) |
| tsbs-scale100_cpu-max-all-1 | 1388 | 1500 | 8.07% |
| tsbs-scale100_double-groupby-1 | 100 | 108 | 8.00% |
| tsbs-scale100_groupby-orderby-limit | 793 | 1282 | 61.66% |
| tsbs-scale100_single-groupby-1-1-1 | 13448 | 21347 | 58.74% |
| tsbs-scale100_single-groupby-1-1-12 | 2383 | 3921 | 64.54% |
We Can Observe an Improvement of 8% to 65% in the Number of Queries per Second Compared to RedisTimeSeries 1.4
Keyspace Notifications
Redis Keyspace Notifications Allow Redis Clients to Subscribe to Pub/Sub Channels in Order to Receive Events Affecting the Redis Data Set in Some Way You Can, for Example, Use RedisGears to Trigger a Function with These Notifications
As an Example It Is Possible to Implement a Time Series Predictor or Anomaly Detector that Listens to the Stream of Samples and Generates Real-time Predictions and Warnings Check, for Example, This Test Which Subscribes to Various RedisTimeSeries Commands and Generates Events
Redis Enterprise Support for Redis on Flash
Since Version 1.6 RedisTimeSeries Can Run in a Redis on Flash but It's Important to Note that RoF Is Implemented on the Key Level Namely the Value of the Whole Time Series Lives Either on FLASH or RAM
RedisTimeSeries Is Part of Redis Stack
RedisTimeSeries ตอนนี้เป็นส่วนหนึ่งของ Redis Stack คุณสามารถ Download Latest Redis Stack Server Binaries สำหรับ macOS, Ubuntu หรือ Redhat หรือ Install ด้วย Docker, Homebrew หรือ Linux
Visualize Time Series Data with RedisInsight
RedisInsight เป็น Visual Tool สำหรับ Developers ที่ให้ Excellent Way to Explore Data from RedisTimeSeries During Development Using Redis or Redis Stack
คุณสามารถ Execute Time Series Queries และ Observe Results Directly from Graphical User Interface RedisInsight Can Now Visualize RedisTimeSeries Query Results
In Addition RedisInsight Contains Quick Guides and Tutorials for Learning RedisTimeSeries Interactively
Learn More on RedisTimeSeries on redis.io and developer.redis.com