@@ -88,7 +88,7 @@ def create(
88
88
self ._append_retention (params , retention_msecs )
89
89
self ._append_uncompressed (params , uncompressed )
90
90
self ._append_chunk_size (params , chunk_size )
91
- self ._append_duplicate_policy (params , CREATE_CMD , duplicate_policy )
91
+ self ._append_duplicate_policy (params , duplicate_policy )
92
92
self ._append_labels (params , labels )
93
93
self ._append_ignore_filters (params , ignore_max_time_diff , ignore_max_val_diff )
94
94
@@ -98,6 +98,7 @@ def alter(
98
98
self ,
99
99
key : KeyT ,
100
100
retention_msecs : Optional [int ] = None ,
101
+ uncompressed : Optional [bool ] = False ,
101
102
labels : Optional [Dict [str , str ]] = None ,
102
103
chunk_size : Optional [int ] = None ,
103
104
duplicate_policy : Optional [str ] = None ,
@@ -117,6 +118,8 @@ def alter(
117
118
retention_msecs:
118
119
Maximum age for samples, compared to the highest reported timestamp in
119
120
milliseconds. If None or 0 is passed, the series is not trimmed at all.
121
+ uncompressed:
122
+ Changes data storage from compressed (default) to uncompressed.
120
123
labels:
121
124
A dictionary of label-value pairs that represent metadata labels of the
122
125
key.
@@ -153,8 +156,9 @@ def alter(
153
156
"""
154
157
params = [key ]
155
158
self ._append_retention (params , retention_msecs )
159
+ self ._append_uncompressed (params , uncompressed )
156
160
self ._append_chunk_size (params , chunk_size )
157
- self ._append_duplicate_policy (params , ALTER_CMD , duplicate_policy )
161
+ self ._append_duplicate_policy (params , duplicate_policy )
158
162
self ._append_labels (params , labels )
159
163
self ._append_ignore_filters (params , ignore_max_time_diff , ignore_max_val_diff )
160
164
@@ -172,6 +176,7 @@ def add(
172
176
duplicate_policy : Optional [str ] = None ,
173
177
ignore_max_time_diff : Optional [int ] = None ,
174
178
ignore_max_val_diff : Optional [Number ] = None ,
179
+ on_duplicate : Optional [str ] = None ,
175
180
):
176
181
"""
177
182
Append (or create and append) a new sample to a time series.
@@ -225,14 +230,18 @@ def add(
225
230
is lower than this threshold, the new entry is ignored. Only applicable
226
231
if `duplicate_policy` is set to `last`, and if `ignore_max_time_diff` is
227
232
also set. Available since RedisTimeSeries version 1.12.0.
233
+ on_duplicate:
234
+ Use a specific duplicate policy for the specified timestamp. Overrides
235
+ the duplicate policy set by `duplicate_policy`.
228
236
"""
229
237
params = [key , timestamp , value ]
230
238
self ._append_retention (params , retention_msecs )
231
239
self ._append_uncompressed (params , uncompressed )
232
240
self ._append_chunk_size (params , chunk_size )
233
- self ._append_duplicate_policy (params , ADD_CMD , duplicate_policy )
241
+ self ._append_duplicate_policy (params , duplicate_policy )
234
242
self ._append_labels (params , labels )
235
243
self ._append_ignore_filters (params , ignore_max_time_diff , ignore_max_val_diff )
244
+ self ._append_on_duplicate (params , on_duplicate )
236
245
237
246
return self .execute_command (ADD_CMD , * params )
238
247
@@ -260,6 +269,9 @@ def incrby(
260
269
uncompressed : Optional [bool ] = False ,
261
270
labels : Optional [Dict [str , str ]] = None ,
262
271
chunk_size : Optional [int ] = None ,
272
+ duplicate_policy : Optional [str ] = None ,
273
+ ignore_max_time_diff : Optional [int ] = None ,
274
+ ignore_max_val_diff : Optional [Number ] = None ,
263
275
):
264
276
"""
265
277
Increment (or create an time-series and increment) the latest sample's of a series.
@@ -276,21 +288,52 @@ def incrby(
276
288
Timestamp of the sample. `*` can be used for automatic timestamp (using
277
289
the system clock).
278
290
retention_msecs:
279
- Maximum age for samples compared to last event time (in milliseconds).
280
- If ` None` or `0` is passed then the series is not trimmed at all.
291
+ Maximum age for samples, compared to the highest reported timestamp in
292
+ milliseconds. If None or 0 is passed, the series is not trimmed at all.
281
293
uncompressed:
282
- Changes data storage from compressed (by default) to uncompressed.
294
+ Changes data storage from compressed (default) to uncompressed.
283
295
labels:
284
- Set of label-value pairs that represent metadata labels of the key.
296
+ A dictionary of label-value pairs that represent metadata labels of the
297
+ key.
285
298
chunk_size:
286
- Memory size, in bytes, allocated for each data chunk.
299
+ Memory size, in bytes, allocated for each data chunk. Must be a multiple
300
+ of 8 in the range [128..1048576].
301
+ duplicate_policy:
302
+ Policy for handling multiple samples with identical timestamps. Can be
303
+ one of:
304
+ - 'block': An error will occur for any out of order sample.
305
+ - 'first': Ignore the new value.
306
+ - 'last': Override with the latest value.
307
+ - 'min': Only override if the value is lower than the existing
308
+ value.
309
+ - 'max': Only override if the value is higher than the existing
310
+ value.
311
+ - 'sum': If a previous sample exists, add the new sample to it so
312
+ that the updated value is equal to (previous + new). If no
313
+ previous sample exists, set the updated value equal to the new
314
+ value.
315
+ ignore_max_time_diff:
316
+ A non-negative integer value, in milliseconds, that sets an ignore
317
+ threshold for added timestamps. If the difference between the last
318
+ timestamp and the new timestamp is lower than this threshold, the new
319
+ entry is ignored. Only applicable if `duplicate_policy` is set to
320
+ `last`, and if `ignore_max_val_diff` is also set. Available since
321
+ RedisTimeSeries version 1.12.0.
322
+ ignore_max_val_diff:
323
+ A non-negative floating point value, that sets an ignore threshold for
324
+ added values. If the difference between the last value and the new value
325
+ is lower than this threshold, the new entry is ignored. Only applicable
326
+ if `duplicate_policy` is set to `last`, and if `ignore_max_time_diff` is
327
+ also set. Available since RedisTimeSeries version 1.12.0.
287
328
"""
288
329
params = [key , value ]
289
330
self ._append_timestamp (params , timestamp )
290
331
self ._append_retention (params , retention_msecs )
291
332
self ._append_uncompressed (params , uncompressed )
292
333
self ._append_chunk_size (params , chunk_size )
334
+ self ._append_duplicate_policy (params , duplicate_policy )
293
335
self ._append_labels (params , labels )
336
+ self ._append_ignore_filters (params , ignore_max_time_diff , ignore_max_val_diff )
294
337
295
338
return self .execute_command (INCRBY_CMD , * params )
296
339
@@ -303,6 +346,9 @@ def decrby(
303
346
uncompressed : Optional [bool ] = False ,
304
347
labels : Optional [Dict [str , str ]] = None ,
305
348
chunk_size : Optional [int ] = None ,
349
+ duplicate_policy : Optional [str ] = None ,
350
+ ignore_max_time_diff : Optional [int ] = None ,
351
+ ignore_max_val_diff : Optional [Number ] = None ,
306
352
):
307
353
"""
308
354
Decrement (or create an time-series and decrement) the latest sample's of a series.
@@ -319,21 +365,52 @@ def decrby(
319
365
Timestamp of the sample. `*` can be used for automatic timestamp (using
320
366
the system clock).
321
367
retention_msecs:
322
- Maximum age for samples compared to last event time (in milliseconds).
323
- If ` None` or `0` is passed then the series is not trimmed at all.
368
+ Maximum age for samples, compared to the highest reported timestamp in
369
+ milliseconds. If None or 0 is passed, the series is not trimmed at all.
324
370
uncompressed:
325
- Changes data storage from compressed (by default) to uncompressed.
371
+ Changes data storage from compressed (default) to uncompressed.
326
372
labels:
327
- Set of label-value pairs that represent metadata labels of the key.
373
+ A dictionary of label-value pairs that represent metadata labels of the
374
+ key.
328
375
chunk_size:
329
- Memory size, in bytes, allocated for each data chunk.
376
+ Memory size, in bytes, allocated for each data chunk. Must be a multiple
377
+ of 8 in the range [128..1048576].
378
+ duplicate_policy:
379
+ Policy for handling multiple samples with identical timestamps. Can be
380
+ one of:
381
+ - 'block': An error will occur for any out of order sample.
382
+ - 'first': Ignore the new value.
383
+ - 'last': Override with the latest value.
384
+ - 'min': Only override if the value is lower than the existing
385
+ value.
386
+ - 'max': Only override if the value is higher than the existing
387
+ value.
388
+ - 'sum': If a previous sample exists, add the new sample to it so
389
+ that the updated value is equal to (previous + new). If no
390
+ previous sample exists, set the updated value equal to the new
391
+ value.
392
+ ignore_max_time_diff:
393
+ A non-negative integer value, in milliseconds, that sets an ignore
394
+ threshold for added timestamps. If the difference between the last
395
+ timestamp and the new timestamp is lower than this threshold, the new
396
+ entry is ignored. Only applicable if `duplicate_policy` is set to
397
+ `last`, and if `ignore_max_val_diff` is also set. Available since
398
+ RedisTimeSeries version 1.12.0.
399
+ ignore_max_val_diff:
400
+ A non-negative floating point value, that sets an ignore threshold for
401
+ added values. If the difference between the last value and the new value
402
+ is lower than this threshold, the new entry is ignored. Only applicable
403
+ if `duplicate_policy` is set to `last`, and if `ignore_max_time_diff` is
404
+ also set. Available since RedisTimeSeries version 1.12.0.
330
405
"""
331
406
params = [key , value ]
332
407
self ._append_timestamp (params , timestamp )
333
408
self ._append_retention (params , retention_msecs )
334
409
self ._append_uncompressed (params , uncompressed )
335
410
self ._append_chunk_size (params , chunk_size )
411
+ self ._append_duplicate_policy (params , duplicate_policy )
336
412
self ._append_labels (params , labels )
413
+ self ._append_ignore_filters (params , ignore_max_time_diff , ignore_max_val_diff )
337
414
338
415
return self .execute_command (DECRBY_CMD , * params )
339
416
@@ -942,17 +1019,16 @@ def _append_chunk_size(params: List[str], chunk_size: Optional[int]):
942
1019
params .extend (["CHUNK_SIZE" , chunk_size ])
943
1020
944
1021
@staticmethod
945
- def _append_duplicate_policy (
946
- params : List [str ], command : Optional [str ], duplicate_policy : Optional [str ]
947
- ):
948
- """Append DUPLICATE_POLICY property to params on CREATE
949
- and ON_DUPLICATE on ADD.
950
- """
1022
+ def _append_duplicate_policy (params : List [str ], duplicate_policy : Optional [str ]):
1023
+ """Append DUPLICATE_POLICY property to params."""
951
1024
if duplicate_policy is not None :
952
- if command == "TS.ADD" :
953
- params .extend (["ON_DUPLICATE" , duplicate_policy ])
954
- else :
955
- params .extend (["DUPLICATE_POLICY" , duplicate_policy ])
1025
+ params .extend (["DUPLICATE_POLICY" , duplicate_policy ])
1026
+
1027
+ @staticmethod
1028
+ def _append_on_duplicate (params : List [str ], on_duplicate : Optional [str ]):
1029
+ """Append ON_DUPLICATE property to params."""
1030
+ if on_duplicate is not None :
1031
+ params .extend (["ON_DUPLICATE" , on_duplicate ])
956
1032
957
1033
@staticmethod
958
1034
def _append_filer_by_ts (params : List [str ], ts_list : Optional [List [int ]]):
0 commit comments