diff --git a/redistimeseries/client.py b/redistimeseries/client.py index 8e7ddad..2610670 100644 --- a/redistimeseries/client.py +++ b/redistimeseries/client.py @@ -46,7 +46,7 @@ def parse_m_get(response): res = [] for item in response: res.append({ nativestr(item[0]) : [list_to_dict(item[1]), - item[2], float(item[3])]}) + item[2][0], float(item[2][1])]}) return res def parseToList(response): @@ -105,12 +105,16 @@ def __init__(self, *args, **kwargs): for k in MODULE_CALLBACKS: self.set_response_callback(k, MODULE_CALLBACKS[k]) - @staticmethod def appendUncompressed(params, uncompressed): if uncompressed: params.extend(['UNCOMPRESSED']) + @staticmethod + def appendWithLabels(params, with_labels): + if with_labels: + params.extend(['WITHLABELS']) + @staticmethod def appendRetention(params, retention): if retention is not None: @@ -264,8 +268,7 @@ def mrange(self, from_time, to_time, filters, count=None, self.appendCount(params, count) if aggregation_type is not None: self.appendAggregation(params, aggregation_type, bucket_size_msec) - if with_labels: - params.extend(['WITHLABELS']) + self.appendWithLabels(params, with_labels) params.extend(['FILTER']) params += filters return self.execute_command(self.MRANGE_CMD, *params) @@ -274,9 +277,11 @@ def get(self, key): """Gets the last sample of ``key``""" return self.execute_command(self.GET_CMD, key) - def mget(self, filters): + def mget(self, filters, with_labels=False): """Get the last samples matching the specific ``filter``.""" - params = ['FILTER'] + params = [] + self.appendWithLabels(params, with_labels) + params.extend(['FILTER']) params += filters return self.execute_command(self.MGET_CMD, *params) diff --git a/test_commands.py b/test_commands.py index a50cc1f..d03ee0b 100644 --- a/test_commands.py +++ b/test_commands.py @@ -151,6 +151,11 @@ def testMGet(self): res = rts.mget(['Taste=That']) self.assertEqual(25, res[0]['2'][2]) + # test with_labels + self.assertEqual({}, res[0]['2'][0]) + res = rts.mget(['Taste=That'], with_labels=True) + self.assertEqual({'Taste': 'That', 'Test': 'This'}, res[0]['2'][0]) + def testInfo(self): '''Test TS.INFO calls''' rts.create(1, retention_msecs=5, labels={'currentLabel' : 'currentData'})