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

update get/mget return value + with_labels #44

Merged
merged 2 commits into from
Jan 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions redistimeseries/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down
5 changes: 5 additions & 0 deletions test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'})
Expand Down