@@ -9,6 +9,11 @@ namespace NRedisStack
9
9
{
10
10
public static class TimeSeriesAux
11
11
{
12
+ public static void AddLatest ( this IList < object > args , bool latest )
13
+ {
14
+ if ( latest ) args . Add ( TimeSeriesArgs . LATEST ) ;
15
+ }
16
+
12
17
public static void AddRetentionTime ( this IList < object > args , long ? retentionTime )
13
18
{
14
19
if ( retentionTime . HasValue )
@@ -76,18 +81,46 @@ public static void AddOnDuplicate(this IList<object> args, TsDuplicatePolicy? po
76
81
}
77
82
}
78
83
79
- public static void AddAlign ( this IList < object > args , TimeStamp align )
84
+ public static void AddAlign ( this IList < object > args , TimeStamp ? align )
80
85
{
81
- if ( align != null )
86
+ if ( align != null )
82
87
{
83
88
args . Add ( TimeSeriesArgs . ALIGN ) ;
84
89
args . Add ( align . Value ) ;
85
90
}
86
91
}
87
92
93
+ public static void AddBucketTimestamp ( this IList < object > args , TsBucketTimestamps ? bt )
94
+ {
95
+ if ( bt != null )
96
+ {
97
+ args . Add ( TimeSeriesArgs . BUCKETTIMESTAMP ) ;
98
+ args . Add ( bt . Value . AsArg ( ) ) ;
99
+ }
100
+ }
101
+
102
+ public static void AddAggregation ( this IList < object > args , TimeStamp ? align ,
103
+ TsAggregation ? aggregation ,
104
+ long ? timeBucket ,
105
+ TsBucketTimestamps ? bt ,
106
+ bool empty )
107
+ {
108
+ if ( aggregation == null && ( align != null || timeBucket != null || bt != null || empty ) )
109
+ {
110
+ throw new ArgumentException ( "align, timeBucket, BucketTimestamps or empty cannot be defined without Aggregation" ) ;
111
+ }
112
+ else
113
+ {
114
+ args . AddAlign ( align ) ;
115
+ args . AddAggregation ( aggregation , timeBucket ) ;
116
+ args . AddBucketTimestamp ( bt ) ;
117
+ if ( empty ) args . Add ( TimeSeriesArgs . EMPTY ) ;
118
+ }
119
+ }
120
+
88
121
public static void AddAggregation ( this IList < object > args , TsAggregation ? aggregation , long ? timeBucket )
89
122
{
90
- if ( aggregation != null )
123
+ if ( aggregation != null )
91
124
{
92
125
args . Add ( TimeSeriesArgs . AGGREGATION ) ;
93
126
args . Add ( aggregation . Value . AsArg ( ) ) ;
@@ -101,18 +134,18 @@ public static void AddAggregation(this IList<object> args, TsAggregation? aggreg
101
134
102
135
public static void AddFilters ( this List < object > args , IReadOnlyCollection < string > filter )
103
136
{
104
- if ( filter == null || filter . Count == 0 )
137
+ if ( filter == null || filter . Count == 0 )
105
138
{
106
139
throw new ArgumentException ( "There should be at least one filter on MRANGE/MREVRANGE" ) ;
107
140
}
108
141
args . Add ( TimeSeriesArgs . FILTER ) ;
109
- foreach ( string f in filter )
142
+ foreach ( string f in filter )
110
143
{
111
144
args . Add ( f ) ;
112
145
}
113
146
}
114
147
115
- public static void AddFilterByTs ( this List < object > args , IReadOnlyCollection < TimeStamp > filter )
148
+ public static void AddFilterByTs ( this List < object > args , IReadOnlyCollection < TimeStamp > ? filter )
116
149
{
117
150
if ( filter != null )
118
151
{
@@ -134,20 +167,23 @@ public static void AddFilterByValue(this List<object> args, (long, long)? filter
134
167
}
135
168
}
136
169
137
- public static void AddWithLabels ( this IList < object > args , bool ? withLabels , IReadOnlyCollection < string > selectLabels = null )
170
+ public static void AddWithLabels ( this IList < object > args , bool ? withLabels , IReadOnlyCollection < string > ? selectLabels = null )
138
171
{
139
- if ( withLabels . HasValue && selectLabels != null ) {
172
+ if ( withLabels . HasValue && selectLabels != null )
173
+ {
140
174
throw new ArgumentException ( "withLabels and selectLabels cannot be specified together." ) ;
141
175
}
142
176
143
- if ( withLabels . HasValue && withLabels . Value )
177
+ if ( withLabels . HasValue && withLabels . Value )
144
178
{
145
179
args . Add ( TimeSeriesArgs . WITHLABELS ) ;
146
180
}
147
181
148
- if ( selectLabels != null ) {
182
+ if ( selectLabels != null )
183
+ {
149
184
args . Add ( TimeSeriesArgs . SELECTEDLABELS ) ;
150
- foreach ( string label in selectLabels ) {
185
+ foreach ( string label in selectLabels )
186
+ {
151
187
args . Add ( label ) ;
152
188
}
153
189
}
@@ -166,7 +202,7 @@ public static void AddGroupby(this IList<object> args, (string groupby, TsReduce
166
202
167
203
public static void AddTimeStamp ( this IList < object > args , TimeStamp timeStamp )
168
204
{
169
- if ( timeStamp != null )
205
+ if ( timeStamp != null )
170
206
{
171
207
args . Add ( TimeSeriesArgs . TIMESTAMP ) ;
172
208
args . Add ( timeStamp . Value ) ;
@@ -184,7 +220,7 @@ public static void AddRule(this IList<object> args, TimeSeriesRule rule)
184
220
public static List < object > BuildTsCreateArgs ( string key , long ? retentionTime , IReadOnlyCollection < TimeSeriesLabel > labels , bool ? uncompressed ,
185
221
long ? chunkSizeBytes , TsDuplicatePolicy ? policy )
186
222
{
187
- var args = new List < object > { key } ;
223
+ var args = new List < object > { key } ;
188
224
args . AddRetentionTime ( retentionTime ) ;
189
225
args . AddChunkSize ( chunkSizeBytes ) ;
190
226
args . AddLabels ( labels ) ;
@@ -193,18 +229,21 @@ public static List<object> BuildTsCreateArgs(string key, long? retentionTime, IR
193
229
return args ;
194
230
}
195
231
196
- public static List < object > BuildTsAlterArgs ( string key , long ? retentionTime , IReadOnlyCollection < TimeSeriesLabel > ? labels )
232
+ public static List < object > BuildTsAlterArgs ( string key , long ? retentionTime , long ? chunkSizeBytes ,
233
+ TsDuplicatePolicy ? policy , IReadOnlyCollection < TimeSeriesLabel > ? labels )
197
234
{
198
- var args = new List < object > { key } ;
235
+ var args = new List < object > { key } ;
199
236
args . AddRetentionTime ( retentionTime ) ;
200
- if ( labels != null ) args . AddLabels ( labels ) ;
237
+ args . AddChunkSize ( chunkSizeBytes ) ;
238
+ args . AddDuplicatePolicy ( policy ) ;
239
+ args . AddLabels ( labels ) ;
201
240
return args ;
202
241
}
203
242
204
243
public static List < object > BuildTsAddArgs ( string key , TimeStamp timestamp , double value , long ? retentionTime ,
205
244
IReadOnlyCollection < TimeSeriesLabel > labels , bool ? uncompressed , long ? chunkSizeBytes , TsDuplicatePolicy ? policy )
206
245
{
207
- var args = new List < object > { key , timestamp . Value , value } ;
246
+ var args = new List < object > { key , timestamp . Value , value } ;
208
247
args . AddRetentionTime ( retentionTime ) ;
209
248
args . AddChunkSize ( chunkSizeBytes ) ;
210
249
args . AddLabels ( labels ) ;
@@ -216,7 +255,7 @@ public static List<object> BuildTsAddArgs(string key, TimeStamp timestamp, doubl
216
255
public static List < object > BuildTsIncrDecrByArgs ( string key , double value , TimeStamp ? timestamp , long ? retentionTime ,
217
256
IReadOnlyCollection < TimeSeriesLabel > ? labels , bool ? uncompressed , long ? chunkSizeBytes )
218
257
{
219
- var args = new List < object > { key , value } ;
258
+ var args = new List < object > { key , value } ;
220
259
if ( timestamp != null ) args . AddTimeStamp ( timestamp ) ;
221
260
args . AddRetentionTime ( retentionTime ) ;
222
261
args . AddChunkSize ( chunkSizeBytes ) ;
@@ -244,51 +283,65 @@ public static List<object> BuildTsMaddArgs(IReadOnlyCollection<(string key, Time
244
283
return args ;
245
284
}
246
285
247
- public static List < object > BuildTsMgetArgs ( IReadOnlyCollection < string > filter , bool ? withLabels )
286
+ public static List < object > BuildTsMgetArgs ( bool latest , IReadOnlyCollection < string > filter , bool ? withLabels = null , IReadOnlyCollection < string > ? selectedLabels = null )
248
287
{
249
288
var args = new List < object > ( ) ;
250
- args . AddWithLabels ( withLabels ) ;
289
+ args . AddLatest ( latest ) ;
290
+ args . AddWithLabels ( withLabels , selectedLabels ) ;
251
291
args . AddFilters ( filter ) ;
252
292
return args ;
253
293
}
254
294
295
+ //TODO: add the new parameters to TS.RANGE
255
296
public static List < object > BuildRangeArgs ( string key ,
256
297
TimeStamp fromTimeStamp ,
257
298
TimeStamp toTimeStamp ,
299
+ bool latest ,
300
+ IReadOnlyCollection < TimeStamp > ? filterByTs ,
301
+ ( long , long ) ? filterByValue ,
258
302
long ? count ,
303
+ TimeStamp ? align ,
259
304
TsAggregation ? aggregation ,
260
305
long ? timeBucket ,
261
- IReadOnlyCollection < TimeStamp > ? filterByTs ,
262
- ( long , long ) ? filterByValue ,
263
- TimeStamp ? align )
306
+ TsBucketTimestamps ? bt ,
307
+ bool empty )
264
308
{
265
309
var args = new List < object > ( )
266
310
{ key , fromTimeStamp . Value , toTimeStamp . Value } ;
267
-
311
+ args . AddLatest ( latest ) ;
268
312
if ( filterByTs != null ) args . AddFilterByTs ( filterByTs ) ;
269
313
args . AddFilterByValue ( filterByValue ) ;
270
314
args . AddCount ( count ) ;
271
- if ( align != null ) args . AddAlign ( align ) ;
272
- args . AddAggregation ( aggregation , timeBucket ) ;
315
+ args . AddAggregation ( align , aggregation , timeBucket , bt , empty ) ;
273
316
return args ;
274
317
}
275
318
276
319
277
- public static List < object > BuildMultiRangeArgs ( TimeStamp fromTimeStamp , TimeStamp toTimeStamp ,
278
- IReadOnlyCollection < string > filter , long ? count , TsAggregation ? aggregation , long ? timeBucket ,
279
- bool ? withLabels , ( string , TsReduce ) ? groupbyTuple , IReadOnlyCollection < TimeStamp > ? filterByTs ,
280
- ( long , long ) ? filterByValue , IReadOnlyCollection < string > ? selectLabels , TimeStamp ? align )
320
+ public static List < object > BuildMultiRangeArgs ( TimeStamp fromTimeStamp ,
321
+ TimeStamp toTimeStamp ,
322
+ IReadOnlyCollection < string > filter ,
323
+ bool latest ,
324
+ IReadOnlyCollection < TimeStamp > ? filterByTs ,
325
+ ( long , long ) ? filterByValue ,
326
+ bool ? withLabels ,
327
+ IReadOnlyCollection < string > ? selectLabels ,
328
+ long ? count ,
329
+ TimeStamp ? align ,
330
+ TsAggregation ? aggregation ,
331
+ long ? timeBucket ,
332
+ TsBucketTimestamps ? bt ,
333
+ bool empty ,
334
+ ( string , TsReduce ) ? groupbyTuple )
281
335
{
282
- var args = new List < object > ( ) { fromTimeStamp . Value , toTimeStamp . Value } ;
283
- if ( filterByTs != null ) args . AddFilterByTs ( filterByTs ) ;
336
+ var args = new List < object > ( ) { fromTimeStamp . Value , toTimeStamp . Value } ;
337
+ args . AddFilterByTs ( filterByTs ) ;
284
338
args . AddFilterByValue ( filterByValue ) ;
285
- args . AddCount ( count ) ;
286
- if ( align != null ) args . AddAlign ( align ) ;
287
- args . AddAggregation ( aggregation , timeBucket ) ;
288
339
args . AddWithLabels ( withLabels , selectLabels ) ;
340
+ args . AddCount ( count ) ;
341
+ args . AddAggregation ( align , aggregation , timeBucket , bt , empty ) ;
289
342
args . AddFilters ( filter ) ;
290
343
args . AddGroupby ( groupbyTuple ) ;
291
344
return args ;
292
345
}
293
346
}
294
- }
347
+ }
0 commit comments