Skip to content
This repository was archived by the owner on Jan 24, 2023. It is now read-only.

Commit 7d0c39e

Browse files
Ariel Shtulgkorland
authored andcommitted
update get/mget return value + with_labels (#44)
* update get/mget return value * add with_labels support
1 parent c27fa0c commit 7d0c39e

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

redistimeseries/client.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def parse_m_get(response):
4646
res = []
4747
for item in response:
4848
res.append({ nativestr(item[0]) : [list_to_dict(item[1]),
49-
item[2], float(item[3])]})
49+
item[2][0], float(item[2][1])]})
5050
return res
5151

5252
def parseToList(response):
@@ -105,12 +105,16 @@ def __init__(self, *args, **kwargs):
105105
for k in MODULE_CALLBACKS:
106106
self.set_response_callback(k, MODULE_CALLBACKS[k])
107107

108-
109108
@staticmethod
110109
def appendUncompressed(params, uncompressed):
111110
if uncompressed:
112111
params.extend(['UNCOMPRESSED'])
113112

113+
@staticmethod
114+
def appendWithLabels(params, with_labels):
115+
if with_labels:
116+
params.extend(['WITHLABELS'])
117+
114118
@staticmethod
115119
def appendRetention(params, retention):
116120
if retention is not None:
@@ -264,8 +268,7 @@ def mrange(self, from_time, to_time, filters, count=None,
264268
self.appendCount(params, count)
265269
if aggregation_type is not None:
266270
self.appendAggregation(params, aggregation_type, bucket_size_msec)
267-
if with_labels:
268-
params.extend(['WITHLABELS'])
271+
self.appendWithLabels(params, with_labels)
269272
params.extend(['FILTER'])
270273
params += filters
271274
return self.execute_command(self.MRANGE_CMD, *params)
@@ -274,9 +277,11 @@ def get(self, key):
274277
"""Gets the last sample of ``key``"""
275278
return self.execute_command(self.GET_CMD, key)
276279

277-
def mget(self, filters):
280+
def mget(self, filters, with_labels=False):
278281
"""Get the last samples matching the specific ``filter``."""
279-
params = ['FILTER']
282+
params = []
283+
self.appendWithLabels(params, with_labels)
284+
params.extend(['FILTER'])
280285
params += filters
281286
return self.execute_command(self.MGET_CMD, *params)
282287

test_commands.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ def testMGet(self):
151151
res = rts.mget(['Taste=That'])
152152
self.assertEqual(25, res[0]['2'][2])
153153

154+
# test with_labels
155+
self.assertEqual({}, res[0]['2'][0])
156+
res = rts.mget(['Taste=That'], with_labels=True)
157+
self.assertEqual({'Taste': 'That', 'Test': 'This'}, res[0]['2'][0])
158+
154159
def testInfo(self):
155160
'''Test TS.INFO calls'''
156161
rts.create(1, retention_msecs=5, labels={'currentLabel' : 'currentData'})

0 commit comments

Comments
 (0)