Repository navigation
Expand file tree
/
Copy pathTimeSeriesCommandsAsync.cs
More file actions
556 lines (505 loc) · 24.1 KB
/
Copy pathTimeSeriesCommandsAsync.cs
File metadata and controls
556 lines (505 loc) · 24.1 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
using StackExchange.Redis;
using NRedisStack.Literals.Enums;
using NRedisStack.DataTypes;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace NRedisStack;
public class TimeSeriesCommandsAsync : ITimeSeriesCommandsAsync
{
readonly IDatabaseAsync _db;
public TimeSeriesCommandsAsync(IDatabaseAsync db)
{
_db = db;
}
#region Create
/// <inheritdoc/>
[Obsolete("Please use the other method with TsCreateParams and check related builder TsCreateParamsBuilder to build parameters.")]
public async Task<bool> CreateAsync(string key, long? retentionTime = null, IReadOnlyCollection<TimeSeriesLabel>? labels = null, bool? uncompressed = null, long? chunkSizeBytes = null, TsDuplicatePolicy? duplicatePolicy = null)
{
return (await _db.ExecuteAsync(TimeSeriesCommandsBuilder.Create(key, retentionTime, labels,
uncompressed, chunkSizeBytes,
duplicatePolicy))).OKtoBoolean();
}
/// <inheritdoc/>
public async Task<bool> CreateAsync(string key, TsCreateParams parameters) => (await _db.ExecuteAsync(TimeSeriesCommandsBuilder.Create(key, parameters))).OKtoBoolean();
#endregion
#region Update
/// <inheritdoc/>
[Obsolete("Please use the other method with TsAlterParams and check related builder TsAlterParamsBuilder to build parameters.")]
public async Task<bool> AlterAsync(string key, long? retentionTime = null, long? chunkSizeBytes = null, TsDuplicatePolicy? duplicatePolicy = null, IReadOnlyCollection<TimeSeriesLabel>? labels = null)
{
return (await _db.ExecuteAsync(TimeSeriesCommandsBuilder.Alter(key, retentionTime, chunkSizeBytes, duplicatePolicy, labels))).OKtoBoolean();
}
/// <inheritdoc/>
public async Task<bool> AlterAsync(string key, TsAlterParams parameters) => (await _db.ExecuteAsync(TimeSeriesCommandsBuilder.Alter(key, parameters))).OKtoBoolean();
/// <inheritdoc/>
[Obsolete("Please use the other method with TsAddParams and check related builder TsAddParamsBuilder to build parameters.")]
public async Task<TimeStamp> AddAsync(string key, TimeStamp timestamp, double value, long? retentionTime = null, IReadOnlyCollection<TimeSeriesLabel>? labels = null, bool? uncompressed = null, long? chunkSizeBytes = null, TsDuplicatePolicy? duplicatePolicy = null)
{
return (await _db.ExecuteAsync(TimeSeriesCommandsBuilder.Add(key, timestamp, value, retentionTime, labels,
uncompressed, chunkSizeBytes, duplicatePolicy))).ToTimeStamp();
}
/// <inheritdoc/>
public async Task<TimeStamp> AddAsync(string key, TsAddParams parameters) => (await _db.ExecuteAsync(TimeSeriesCommandsBuilder.Add(key, parameters))).ToTimeStamp();
/// <inheritdoc/>
public async Task<IReadOnlyList<TimeStamp>> MAddAsync(IReadOnlyCollection<(string key, TimeStamp timestamp, double value)> sequence)
{
return (await _db.ExecuteAsync(TimeSeriesCommandsBuilder.MAdd(sequence))).ToTimeStampArray();
}
/// <inheritdoc/>
public async Task<TimeStamp> IncrByAsync(string key, double value, TimeStamp? timestamp = null, long? retentionTime = null, IReadOnlyCollection<TimeSeriesLabel>? labels = null, bool? uncompressed = null, long? chunkSizeBytes = null)
{
return (await _db.ExecuteAsync(
#pragma warning disable CS0612
TimeSeriesCommandsBuilder.IncrBy(
#pragma warning restore CS0612
key, value, timestamp, retentionTime,
labels, uncompressed, chunkSizeBytes))).ToTimeStamp();
}
[Obsolete("Please use the other method with TsIncrByParams and check related builder TsIncryByParamsBuilder to build parameters.")]
public async Task<TimeStamp> IncrByAsync(string key, TsIncrByParams parameters) => (await _db.ExecuteAsync(TimeSeriesCommandsBuilder.IncrBy(key, parameters))).ToTimeStamp();
/// <inheritdoc/>
public async Task<TimeStamp> DecrByAsync(string key, double value, TimeStamp? timestamp = null, long? retentionTime = null, IReadOnlyCollection<TimeSeriesLabel>? labels = null, bool? uncompressed = null, long? chunkSizeBytes = null)
{
return (await _db.ExecuteAsync(
#pragma warning disable CS0612
TimeSeriesCommandsBuilder.DecrBy(
#pragma warning restore CS0612
key, value, timestamp, retentionTime,
labels, uncompressed, chunkSizeBytes))).ToTimeStamp();
}
[Obsolete("Please use the other method with TsDecrByParams and check related builder TsDecryByParamsBuilder to build parameters.")]
public async Task<TimeStamp> DecrByAsync(string key, TsDecrByParams parameters) => (await _db.ExecuteAsync(TimeSeriesCommandsBuilder.DecrBy(key, parameters))).ToTimeStamp();
/// <inheritdoc/>
public async Task<long> DelAsync(string key, TimeStamp fromTimeStamp, TimeStamp toTimeStamp)
{
return (await _db.ExecuteAsync(TimeSeriesCommandsBuilder.Del(key, fromTimeStamp, toTimeStamp))).ToLong();
}
#endregion
#region Aggregation, Compaction, Downsampling
/// <inheritdoc/>
public async Task<bool> CreateRuleAsync(string sourceKey, TimeSeriesRule rule, long alignTimestamp = 0)
{
return (await _db.ExecuteAsync(TimeSeriesCommandsBuilder.CreateRule(sourceKey, rule, alignTimestamp))).OKtoBoolean();
}
/// <inheritdoc/>
public async Task<bool> DeleteRuleAsync(string sourceKey, string destKey)
{
return (await _db.ExecuteAsync(TimeSeriesCommandsBuilder.DeleteRule(sourceKey, destKey))).OKtoBoolean();
}
#endregion
#region Query
/// <inheritdoc/>
public async Task<TimeSeriesTuple?> GetAsync(string key, bool latest = false)
{
return (await _db.ExecuteAsync(TimeSeriesCommandsBuilder.Get(key, latest))).ToTimeSeriesTuple();
}
/// <inheritdoc/>
public async Task<IReadOnlyList<(string key, IReadOnlyList<TimeSeriesLabel> labels, TimeSeriesTuple value)>> MGetAsync(IReadOnlyCollection<string> filter, bool latest = false,
bool? withLabels = null, IReadOnlyCollection<string>? selectedLabels = null)
{
return (await _db.ExecuteAsync(TimeSeriesCommandsBuilder.MGet(filter, latest, withLabels, selectedLabels))).ParseMGetResponse();
}
/// <inheritdoc/>
[OverloadResolutionPriority(1)]
public async Task<IReadOnlyList<TimeSeriesTuple>> RangeAsync(string key,
TimeStamp fromTimeStamp,
TimeStamp toTimeStamp,
bool latest = false,
IReadOnlyCollection<TimeStamp>? filterByTs = null,
(double, double)? filterByValue = null,
long? count = null,
TimeStamp? align = null,
TsAggregations aggregation = default,
long? timeBucket = null,
TsBucketTimestamps? bt = null,
bool empty = false)
{
return (await _db.ExecuteAsync(TimeSeriesCommandsBuilder.Range(key, fromTimeStamp, toTimeStamp,
latest, filterByTs, filterByValue,
count, align, aggregation, timeBucket,
bt, empty))).ToTimeSeriesTupleArray();
}
/// <inheritdoc/>
// retained for binary compatibility with 1.4.0-1.6.0 (filterByValue was (long, long)); de-prioritised
// and hidden so the (double, double) overload always wins overload resolution for new callers.
[Obsolete]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[OverloadResolutionPriority(-1)]
public async Task<IReadOnlyList<TimeSeriesTuple>> RangeAsync(string key,
TimeStamp fromTimeStamp,
TimeStamp toTimeStamp,
bool latest = false,
IReadOnlyCollection<TimeStamp>? filterByTs = null,
(long, long)? filterByValue = null,
long? count = null,
TimeStamp? align = null,
TsAggregations aggregation = default,
long? timeBucket = null,
TsBucketTimestamps? bt = null,
bool empty = false)
{
return await RangeAsync(key, fromTimeStamp, toTimeStamp, latest, filterByTs, filterByValue, count, align, aggregation, timeBucket, bt, empty);
}
/// <inheritdoc/>
[Obsolete]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[OverloadResolutionPriority(-1)]
public async Task<IReadOnlyList<TimeSeriesTuple>> RangeAsync(string key,
TimeStamp fromTimeStamp,
TimeStamp toTimeStamp,
bool latest = false,
IReadOnlyCollection<TimeStamp>? filterByTs = null,
(long, long)? filterByValue = null,
long? count = null,
TimeStamp? align = null,
TsAggregation? aggregation = null,
long? timeBucket = null,
TsBucketTimestamps? bt = null,
bool empty = false)
{
return await RangeAsync(key, fromTimeStamp, toTimeStamp, latest, filterByTs, filterByValue, count, align, (TsAggregations)aggregation, timeBucket, bt, empty);
}
/// <inheritdoc/>
[OverloadResolutionPriority(1)]
public async Task<IReadOnlyList<TimeSeriesTuple>> RevRangeAsync(string key,
TimeStamp fromTimeStamp,
TimeStamp toTimeStamp,
bool latest = false,
IReadOnlyCollection<TimeStamp>? filterByTs = null,
(double, double)? filterByValue = null,
long? count = null,
TimeStamp? align = null,
TsAggregations aggregation = default,
long? timeBucket = null,
TsBucketTimestamps? bt = null,
bool empty = false)
{
return (await _db.ExecuteAsync(TimeSeriesCommandsBuilder.RevRange(key, fromTimeStamp, toTimeStamp,
latest, filterByTs, filterByValue,
count, align, aggregation, timeBucket,
bt, empty))).ToTimeSeriesTupleArray();
}
/// <inheritdoc/>
// retained for binary compatibility with 1.4.0-1.6.0 (filterByValue was (long, long)); de-prioritised
// and hidden so the (double, double) overload always wins overload resolution for new callers.
[Obsolete]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[OverloadResolutionPriority(-1)]
public async Task<IReadOnlyList<TimeSeriesTuple>> RevRangeAsync(string key,
TimeStamp fromTimeStamp,
TimeStamp toTimeStamp,
bool latest = false,
IReadOnlyCollection<TimeStamp>? filterByTs = null,
(long, long)? filterByValue = null,
long? count = null,
TimeStamp? align = null,
TsAggregations aggregation = default,
long? timeBucket = null,
TsBucketTimestamps? bt = null,
bool empty = false)
{
return await RevRangeAsync(key, fromTimeStamp, toTimeStamp, latest, filterByTs, filterByValue, count, align, aggregation, timeBucket, bt, empty);
}
/// <inheritdoc/>
[Obsolete]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[OverloadResolutionPriority(-1)]
public async Task<IReadOnlyList<TimeSeriesTuple>> RevRangeAsync(string key,
TimeStamp fromTimeStamp,
TimeStamp toTimeStamp,
bool latest = false,
IReadOnlyCollection<TimeStamp>? filterByTs = null,
(long, long)? filterByValue = null,
long? count = null,
TimeStamp? align = null,
TsAggregation? aggregation = null,
long? timeBucket = null,
TsBucketTimestamps? bt = null,
bool empty = false)
{
return await RevRangeAsync(key, fromTimeStamp, toTimeStamp, latest, filterByTs, filterByValue, count, align, (TsAggregations)aggregation, timeBucket, bt, empty);
}
/// <inheritdoc/>
[OverloadResolutionPriority(2)]
public async Task<IReadOnlyList<(string key, IReadOnlyList<TimeSeriesLabel> labels, IReadOnlyList<TimeSeriesTuple> values)>> MRangeAsync(
TimeStamp fromTimeStamp,
TimeStamp toTimeStamp,
IReadOnlyCollection<string> filter,
TimeSeriesRangeFlags flags = TimeSeriesRangeFlags.None,
IReadOnlyCollection<TimeStamp>? filterByTs = null,
(double, double)? filterByValue = null,
IReadOnlyCollection<string>? selectLabels = null,
long? count = null,
TimeStamp? align = null,
TsAggregations aggregation = default,
long? timeBucket = null,
TsBucketTimestamps? bt = null,
(string, TsReduce)? groupbyTuple = null)
{
return (await _db.ExecuteAsync(TimeSeriesCommandsBuilder.MRange(fromTimeStamp, toTimeStamp, filter,
flags, filterByTs, filterByValue,
selectLabels, count, align,
aggregation, timeBucket, bt,
groupbyTuple))).ParseMRangeResponse();
}
/// <inheritdoc/>
[OverloadResolutionPriority(1)]
public async Task<IReadOnlyList<(string key, IReadOnlyList<TimeSeriesLabel> labels, IReadOnlyList<TimeSeriesTuple> values)>> MRangeAsync(
TimeStamp fromTimeStamp,
TimeStamp toTimeStamp,
IReadOnlyCollection<string> filter,
bool latest = false,
IReadOnlyCollection<TimeStamp>? filterByTs = null,
(double, double)? filterByValue = null,
bool? withLabels = null,
IReadOnlyCollection<string>? selectLabels = null,
long? count = null,
TimeStamp? align = null,
TsAggregations aggregation = default,
long? timeBucket = null,
TsBucketTimestamps? bt = null,
bool empty = false,
(string, TsReduce)? groupbyTuple = null)
{
return (await _db.ExecuteAsync(TimeSeriesCommandsBuilder.MRange(fromTimeStamp, toTimeStamp, filter,
latest, filterByTs, filterByValue,
withLabels, selectLabels, count, align,
aggregation, timeBucket, bt, empty,
groupbyTuple))).ParseMRangeResponse();
}
/// <inheritdoc/>
// retained for binary compatibility with 1.4.0-1.6.0 (filterByValue was (long, long)); de-prioritised
// and hidden so the (double, double) overload always wins overload resolution for new callers.
[Obsolete]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[OverloadResolutionPriority(-1)]
public async Task<IReadOnlyList<(string key, IReadOnlyList<TimeSeriesLabel> labels, IReadOnlyList<TimeSeriesTuple> values)>> MRangeAsync(
TimeStamp fromTimeStamp,
TimeStamp toTimeStamp,
IReadOnlyCollection<string> filter,
bool latest = false,
IReadOnlyCollection<TimeStamp>? filterByTs = null,
(long, long)? filterByValue = null,
bool? withLabels = null,
IReadOnlyCollection<string>? selectLabels = null,
long? count = null,
TimeStamp? align = null,
TsAggregations aggregation = default,
long? timeBucket = null,
TsBucketTimestamps? bt = null,
bool empty = false,
(string, TsReduce)? groupbyTuple = null)
{
return await MRangeAsync(fromTimeStamp, toTimeStamp, filter, latest, filterByTs, filterByValue, withLabels, selectLabels, count, align, aggregation, timeBucket, bt, empty, groupbyTuple);
}
/// <inheritdoc/>
[Obsolete]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[OverloadResolutionPriority(-1)]
public async Task<IReadOnlyList<(string key, IReadOnlyList<TimeSeriesLabel> labels, IReadOnlyList<TimeSeriesTuple> values)>> MRangeAsync(
TimeStamp fromTimeStamp,
TimeStamp toTimeStamp,
IReadOnlyCollection<string> filter,
bool latest = false,
IReadOnlyCollection<TimeStamp>? filterByTs = null,
(long, long)? filterByValue = null,
bool? withLabels = null,
IReadOnlyCollection<string>? selectLabels = null,
long? count = null,
TimeStamp? align = null,
TsAggregation? aggregation = null,
long? timeBucket = null,
TsBucketTimestamps? bt = null,
bool empty = false,
(string, TsReduce)? groupbyTuple = null)
{
return await MRangeAsync(fromTimeStamp, toTimeStamp, filter, latest, filterByTs, filterByValue, withLabels, selectLabels, count, align, (TsAggregations)aggregation, timeBucket, bt, empty, groupbyTuple);
}
/// <inheritdoc/>
[OverloadResolutionPriority(2)]
public async Task<IReadOnlyList<(string key, IReadOnlyList<TimeSeriesLabel> labels, IReadOnlyList<TimeSeriesTuple> values)>> MRevRangeAsync(
TimeStamp fromTimeStamp,
TimeStamp toTimeStamp,
IReadOnlyCollection<string> filter,
TimeSeriesRangeFlags flags = TimeSeriesRangeFlags.None,
IReadOnlyCollection<TimeStamp>? filterByTs = null,
(double, double)? filterByValue = null,
IReadOnlyCollection<string>? selectLabels = null,
long? count = null,
TimeStamp? align = null,
TsAggregations aggregation = default,
long? timeBucket = null,
TsBucketTimestamps? bt = null,
(string, TsReduce)? groupbyTuple = null)
{
return (await _db.ExecuteAsync(TimeSeriesCommandsBuilder.MRevRange(fromTimeStamp, toTimeStamp, filter,
flags, filterByTs, filterByValue,
selectLabels, count, align,
aggregation, timeBucket, bt,
groupbyTuple))).ParseMRangeResponse();
}
/// <inheritdoc/>
[OverloadResolutionPriority(1)]
public async Task<IReadOnlyList<(string key, IReadOnlyList<TimeSeriesLabel> labels, IReadOnlyList<TimeSeriesTuple> values)>> MRevRangeAsync(
TimeStamp fromTimeStamp,
TimeStamp toTimeStamp,
IReadOnlyCollection<string> filter,
bool latest = false,
IReadOnlyCollection<TimeStamp>? filterByTs = null,
(double, double)? filterByValue = null,
bool? withLabels = null,
IReadOnlyCollection<string>? selectLabels = null,
long? count = null,
TimeStamp? align = null,
TsAggregations aggregation = default,
long? timeBucket = null,
TsBucketTimestamps? bt = null,
bool empty = false,
(string, TsReduce)? groupbyTuple = null)
{
return (await _db.ExecuteAsync(TimeSeriesCommandsBuilder.MRevRange(fromTimeStamp, toTimeStamp, filter,
latest, filterByTs, filterByValue,
withLabels, selectLabels, count, align,
aggregation, timeBucket, bt, empty,
groupbyTuple))).ParseMRangeResponse();
}
/// <inheritdoc/>
// retained for binary compatibility with 1.4.0-1.6.0 (filterByValue was (long, long)); de-prioritised
// and hidden so the (double, double) overload always wins overload resolution for new callers.
[Obsolete]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[OverloadResolutionPriority(-1)]
public async Task<IReadOnlyList<(string key, IReadOnlyList<TimeSeriesLabel> labels, IReadOnlyList<TimeSeriesTuple> values)>> MRevRangeAsync(
TimeStamp fromTimeStamp,
TimeStamp toTimeStamp,
IReadOnlyCollection<string> filter,
bool latest = false,
IReadOnlyCollection<TimeStamp>? filterByTs = null,
(long, long)? filterByValue = null,
bool? withLabels = null,
IReadOnlyCollection<string>? selectLabels = null,
long? count = null,
TimeStamp? align = null,
TsAggregations aggregation = default,
long? timeBucket = null,
TsBucketTimestamps? bt = null,
bool empty = false,
(string, TsReduce)? groupbyTuple = null)
{
return await MRevRangeAsync(fromTimeStamp, toTimeStamp, filter, latest, filterByTs, filterByValue, withLabels, selectLabels, count, align, aggregation, timeBucket, bt, empty, groupbyTuple);
}
/// <inheritdoc/>
[Obsolete]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[OverloadResolutionPriority(-1)]
public async Task<IReadOnlyList<(string key, IReadOnlyList<TimeSeriesLabel> labels, IReadOnlyList<TimeSeriesTuple> values)>> MRevRangeAsync(
TimeStamp fromTimeStamp,
TimeStamp toTimeStamp,
IReadOnlyCollection<string> filter,
bool latest = false,
IReadOnlyCollection<TimeStamp>? filterByTs = null,
(long, long)? filterByValue = null,
bool? withLabels = null,
IReadOnlyCollection<string>? selectLabels = null,
long? count = null,
TimeStamp? align = null,
TsAggregation? aggregation = null,
long? timeBucket = null,
TsBucketTimestamps? bt = null,
bool empty = false,
(string, TsReduce)? groupbyTuple = null)
{
return await MRevRangeAsync(fromTimeStamp, toTimeStamp, filter, latest, filterByTs, filterByValue, withLabels, selectLabels, count, align, (TsAggregations)aggregation, timeBucket, bt, empty, groupbyTuple);
}
#endregion
#region General
/// <inheritdoc/>
public async Task<TimeSeriesInformation> InfoAsync(string key, bool debug = false)
{
return (await _db.ExecuteAsync(TimeSeriesCommandsBuilder.Info(key, debug))).ToTimeSeriesInfo();
}
/// <inheritdoc/>
public async Task<IReadOnlyList<string>> QueryIndexAsync(IReadOnlyCollection<string> filter)
{
return (await _db.ExecuteAsync(TimeSeriesCommandsBuilder.QueryIndex(filter))).ToStringList();
}
/// <inheritdoc/>
public async Task<IReadOnlyList<string>> QueryLabelNamesAsync(IReadOnlyCollection<string>? filter = null)
{
return (await _db.ExecuteAsync(TimeSeriesCommandsBuilder.QueryLabelNames(filter))).ToStringList();
}
/// <inheritdoc/>
public async Task<IReadOnlyList<string>> QueryLabelValuesAsync(string label, IReadOnlyCollection<string>? filter = null)
{
return (await _db.ExecuteAsync(TimeSeriesCommandsBuilder.QueryLabelValues(label, filter))).ToStringList();
}
/// <inheritdoc/>
public async Task<IReadOnlyList<TimeSeriesPivotRow>> NRangeAsync(
IReadOnlyList<string> keys,
TimeStamp fromTimeStamp,
TimeStamp toTimeStamp,
TimeSeriesRangeFlags flags = TimeSeriesRangeFlags.None,
IReadOnlyCollection<TimeStamp>? filterByTs = null,
(double, double)? filterByValue = null,
long? count = null,
TimeStamp? align = null,
IReadOnlyList<TsAggregations>? aggregations = null,
long? timeBucket = null,
TsBucketTimestamps? bt = null)
{
return (await _db.ExecuteAsync(TimeSeriesCommandsBuilder.NRange(keys, fromTimeStamp, toTimeStamp, flags,
filterByTs, filterByValue, count, align, aggregations, timeBucket, bt))).ToTimeSeriesPivotRowArray();
}
/// <inheritdoc/>
public async Task<IReadOnlyList<TimeSeriesPivotRow>> NRevRangeAsync(
IReadOnlyList<string> keys,
TimeStamp fromTimeStamp,
TimeStamp toTimeStamp,
TimeSeriesRangeFlags flags = TimeSeriesRangeFlags.None,
IReadOnlyCollection<TimeStamp>? filterByTs = null,
(double, double)? filterByValue = null,
long? count = null,
TimeStamp? align = null,
IReadOnlyList<TsAggregations>? aggregations = null,
long? timeBucket = null,
TsBucketTimestamps? bt = null)
{
return (await _db.ExecuteAsync(TimeSeriesCommandsBuilder.NRevRange(keys, fromTimeStamp, toTimeStamp, flags,
filterByTs, filterByValue, count, align, aggregations, timeBucket, bt))).ToTimeSeriesPivotRowArray();
}
/// <inheritdoc/>
public async Task<IReadOnlyList<TimeSeriesTuple>> ReadAsync(string key, TimeStamp timestamp, long? maxCount = null)
{
return (await _db.ExecuteAsync(TimeSeriesCommandsBuilder.Read(key, timestamp, maxCount))).ToTimeSeriesTupleArray();
}
/// <inheritdoc/>
public async IAsyncEnumerable<TimeSeriesTuple> ReadAsyncEnumerable(string key, TimeStamp fromTimeStamp,
long? batchSize = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
{
TimeStamp cursor = fromTimeStamp;
while (true)
{
cancellationToken.ThrowIfCancellationRequested();
var batch = await ReadAsync(key, cursor, batchSize);
if (batch.Count == 0) yield break;
foreach (var tuple in batch) yield return tuple;
// stop when the page is not full (drained); otherwise advance the cursor past the last sample.
if (batchSize is not { } size || batch.Count < size) yield break;
long last = batch[batch.Count - 1].Time;
// a full page ending at the max timestamp is drained: nothing can exist beyond it, and last + 1
// would overflow to a negative cursor and issue an invalid TS.READ. Terminate cleanly instead.
if (last == long.MaxValue) yield break;
cursor = last + 1;
}
}
#endregion
}