@@ -109,17 +109,22 @@ def __init__(self, *args, **kwargs):
109109 def appendRetention (params , retention ):
110110 if retention is not None :
111111 params .extend (['RETENTION' , retention ])
112-
112+
113113 @staticmethod
114114 def appendLabels (params , labels ):
115115 if labels :
116116 params .append ('LABELS' )
117117 for k , v in labels .items ():
118118 params .extend ([k ,v ])
119+
120+ @staticmethod
121+ def appendCount (params , count ):
122+ if count is not None :
123+ params .extend (['COUNT' , count ])
119124
120125 @staticmethod
121126 def appendAggregation (params , aggregation_type ,
122- bucket_size_msec ):
127+ bucket_size_msec ):
123128 params .append ('AGGREGATION' )
124129 params .extend ([aggregation_type , bucket_size_msec ])
125130
@@ -218,32 +223,39 @@ def deleterule(self, source_key, dest_key):
218223 """Deletes a compaction rule"""
219224 return self .execute_command (self .DELETERULE_CMD , source_key , dest_key )
220225
221- def range (self , key , from_time , to_time ,
226+ def range (self , key , from_time , to_time , count = None ,
222227 aggregation_type = None , bucket_size_msec = 0 ):
223228 """
224229 Query a range from ``key``, from ``from_time`` to ``to_time``.
230+ ``count`` limits the number of results.
225231 Can Aggregate for ``bucket_size_msec`` where an ``aggregation_type``
226232 can be ['avg', 'sum', 'min', 'max', 'range', 'count', 'first',
227233 'last', 'std.p', 'std.s', 'var.p', 'var.s']
228234 """
229235 params = [key , from_time , to_time ]
230- if aggregation_type != None :
236+ self .appendCount (params , count )
237+ if aggregation_type is not None :
231238 self .appendAggregation (params , aggregation_type , bucket_size_msec )
232239
233240 return self .execute_command (self .RANGE_CMD , * params )
234241
235- def mrange (self , from_time , to_time , filters ,
236- aggregation_type = None , bucket_size_msec = 0 ):
242+ def mrange (self , from_time , to_time , filters , count = None ,
243+ aggregation_type = None , bucket_size_msec = 0 , with_labels = False ):
237244 """
238245 Query a range based on filters,retention_msecs from ``from_time`` to ``to_time``.
246+ ``count`` limits the number of results.
239247 ``filters`` are a list strings such as ['Test=This'].
240248 Can Aggregate for ``bucket_size_msec`` where an ``aggregation_type``
241249 can be ['avg', 'sum', 'min', 'max', 'range', 'count', 'first',
242250 'last', 'std.p', 'std.s', 'var.p', 'var.s']
251+ ``WITHLABELS`` appends labels to results.
243252 """
244253 params = [from_time , to_time ]
245- if aggregation_type != None :
254+ self .appendCount (params , count )
255+ if aggregation_type is not None :
246256 self .appendAggregation (params , aggregation_type , bucket_size_msec )
257+ if with_labels :
258+ params .extend (['WITHLABELS' ])
247259 params .extend (['FILTER' ])
248260 params += filters
249261 return self .execute_command (self .MRANGE_CMD , * params )
0 commit comments