Skip to content

Commit c26cbf3

Browse files
authored
fix #56 add support for FT.MGET (#57)
1 parent 9156402 commit c26cbf3

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

redisearch/client.py

+13
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ class Client(object):
113113
DICT_ADD_CMD = 'FT.DICTADD'
114114
DICT_DEL_CMD = 'FT.DICTDEL'
115115
DICT_DUMP_CMD = 'FT.DICTDUMP'
116+
GET_CMD = 'FT.GET'
117+
MGET_CMD = 'FT.MGET'
116118

117119

118120
NOOFFSETS = 'NOOFFSETS'
@@ -301,6 +303,17 @@ def load_document(self, id):
301303

302304
return Document(id=id, **fields)
303305

306+
def get(self, *ids):
307+
"""
308+
Returns the full contents of multiple documents.
309+
310+
### Parameters
311+
312+
- **ids**: the ids of the saved documents.
313+
"""
314+
315+
return self.redis.execute_command('FT.MGET', self.index_name, *ids)
316+
304317
def info(self):
305318
"""
306319
Get info an stats about the the current index, including the number of documents, memory consumption, etc

test/test.py

+13
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,19 @@ def testDictOps(self):
568568
# Remove rest of the items before reload
569569
client.dict_del('custom_dict', *res)
570570

571+
def testGet(self):
572+
client = self.getCleanClient('idx')
573+
client.create_index((TextField('f1'), TextField('f2')))
574+
575+
self.assertEqual([None], client.get('doc1'))
576+
self.assertEqual([None, None], client.get('doc2', 'doc1'))
577+
578+
client.add_document('doc1', f1='some valid content dd1', f2='this is sample text ff1')
579+
client.add_document('doc2', f1='some valid content dd2', f2='this is sample text ff2')
580+
581+
self.assertEqual([['f1', 'some valid content dd2', 'f2', 'this is sample text ff2']], client.get('doc2'))
582+
self.assertEqual([['f1', 'some valid content dd1', 'f2', 'this is sample text ff1'], ['f1', 'some valid content dd2', 'f2', 'this is sample text ff2']], client.get('doc1', 'doc2'))
583+
571584

572585
if __name__ == '__main__':
573586

0 commit comments

Comments
 (0)