Skip to content

Support FT.CONFIG command #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 10, 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
28 changes: 28 additions & 0 deletions redisearch/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class Client(object):
DICT_DUMP_CMD = 'FT.DICTDUMP'
GET_CMD = 'FT.GET'
MGET_CMD = 'FT.MGET'
CONFIG_CMD = 'FT.CONFIG'

NOOFFSETS = 'NOOFFSETS'
NOFIELDS = 'NOFIELDS'
Expand Down Expand Up @@ -566,3 +567,30 @@ def dict_dump(self, name):
cmd = [self.DICT_DUMP_CMD, name]
raw = self.redis.execute_command(*cmd)
return raw

def config_set(self, option, value):
"""Set runtime configuration option.

### Parameters

- **option**: the name of the configuration option.
- **value**: a value for the configuration option.
"""
cmd = [self.CONFIG_CMD, 'SET', option, value]
raw = self.redis.execute_command(*cmd)
return raw == 'OK'

def config_get(self, option):
"""Get runtime configuration option value.

### Parameters

- **option**: the name of the configuration option.
"""
cmd = [self.CONFIG_CMD, 'GET', option]
res = {}
raw = self.redis.execute_command(*cmd)
if raw:
for kvs in raw:
res[kvs[0]] = kvs[1]
return res
10 changes: 9 additions & 1 deletion test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,15 @@ def testGet(self):
self.assertEqual([['f1', 'some valid content dd2', 'f2', 'this is sample text ff2']], client.get('doc2'))
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'))

def testConfig(self):
client = self.getCleanClient('idx')
self.assertTrue(client.config_set('TIMEOUT', '100'))
self.assertFalse(client.config_set('TIMEOUT', "null"))
res = client.config_get('*')
self.assertEqual('100', res['TIMEOUT'])
res = client.config_get('TIMEOUT')
self.assertEqual('100', res['TIMEOUT'])

def testAggregations(self):
conn = self.redis()

Expand Down Expand Up @@ -772,7 +781,6 @@ def testAggregations(self):
self.assertEqual(b'RediSearch', res[23])
self.assertEqual(2, len(res[25]))


if __name__ == '__main__':

unittest.main()