-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathRangeExampleAsync.cs
84 lines (80 loc) · 4.08 KB
/
RangeExampleAsync.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using NRedisTimeSeries.Commands.Enums;
using NRedisTimeSeries.DataTypes;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace NRedisTimeSeries.Example
{
/// <summary>
/// Examples for NRedisTimeSeries async API for RANGE queries.
/// </summary>
public class RangeAsyncExample
{
/// <summary>
/// Example for basic usage of RedisTimeSeries RANGE command with "-" and "+" as range boundreis.
/// NRedisTimeSeris Range is expecting two TimeStamps objects as the range boundries.
/// In this case, the strings are implicitly casted into TimeStamp objects.
/// The TimeSeriesRange command returns an IReadOnlyList<TimeSeriesTuple> collection.
/// </summary>
public static async Task DefaultRangeAsyncExample()
{
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
IDatabase db = redis.GetDatabase();
IReadOnlyList<TimeSeriesTuple> results = await db.TimeSeriesRangeAsync("my_ts", "-", "+");
foreach(TimeSeriesTuple res in results) {
Console.WriteLine(res);
}
redis.Close();
}
/// <summary>
/// Example for basic usage of RedisTimeSeries RANGE command with "-" and "+" as range boundreis, and the COUNT parameter.
/// NRedisTimeSeris Range is expecting two TimeStamps objects as the range boundries.
/// In this case, the strings are implicitly casted into TimeStamp objects.
/// The TimeSeriesRange command returns an IReadOnlyList<TimeSeriesTuple> collection.
/// </summary>
public static async Task CountRangeAsyncExample()
{
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
IDatabase db = redis.GetDatabase();
IReadOnlyList<TimeSeriesTuple> results = await db.TimeSeriesRangeAsync("my_ts", "-", "+", count:50);
foreach(TimeSeriesTuple res in results) {
Console.WriteLine(res);
}
redis.Close();
}
/// <summary>
/// Example for basic usage of RedisTimeSeries RANGE command with "-" and "+" as range boundreis, and MIN aggregation.
/// NRedisTimeSeris Range is expecting two TimeStamps objects as the range boundries.
/// In this case, the strings are implicitly casted into TimeStamp objects.
/// The TimeSeriesRange command returns an IReadOnlyList<TimeSeriesTuple> collection.
/// </summary>
public static async Task RangeAggregationAsyncExample()
{
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
IDatabase db = redis.GetDatabase();
IReadOnlyList<TimeSeriesTuple> results = await db.TimeSeriesRangeAsync("my_ts", "-", "+", aggregation: TsAggregation.Min, timeBucket: 50);
foreach(TimeSeriesTuple res in results) {
Console.WriteLine(res);
}
redis.Close();
}
/// <summary>
/// Example for basic usage of RedisTimeSeries RANGE command with "-" and "+" as range boundreis, FILTER_BY_TS, and FILTER_BY_VALUE.
/// NRedisTimeSeris Range is expecting two TimeStamps objects as the range boundries.
/// In this case, the strings are implicitly casted into TimeStamp objects.
/// The TimeSeriesRange command returns an IReadOnlyList<TimeSeriesTuple> collection.
/// </summary>
public static async Task RangeFilterByExample()
{
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
IDatabase db = redis.GetDatabase();
var filterTs = new List<TimeStamp> {0, 50, 100};
IReadOnlyList<TimeSeriesTuple> results = await db.TimeSeriesRangeAsync("my_ts", "-", "+", filterByTs: filterTs, filterByValue: (2, 5));
foreach(TimeSeriesTuple res in results) {
Console.WriteLine(res);
}
redis.Close();
}
}
}