Skip to content

Commit be43fe8

Browse files
authored
Support FT.CONFIG command (#60)
* Support FT.CONFIG command
1 parent ae049ff commit be43fe8

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

redisearch/client.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ class Client(object):
121121
DICT_DUMP_CMD = 'FT.DICTDUMP'
122122
GET_CMD = 'FT.GET'
123123
MGET_CMD = 'FT.MGET'
124+
CONFIG_CMD = 'FT.CONFIG'
124125

125126
NOOFFSETS = 'NOOFFSETS'
126127
NOFIELDS = 'NOFIELDS'
@@ -566,3 +567,30 @@ def dict_dump(self, name):
566567
cmd = [self.DICT_DUMP_CMD, name]
567568
raw = self.redis.execute_command(*cmd)
568569
return raw
570+
571+
def config_set(self, option, value):
572+
"""Set runtime configuration option.
573+
574+
### Parameters
575+
576+
- **option**: the name of the configuration option.
577+
- **value**: a value for the configuration option.
578+
"""
579+
cmd = [self.CONFIG_CMD, 'SET', option, value]
580+
raw = self.redis.execute_command(*cmd)
581+
return raw == 'OK'
582+
583+
def config_get(self, option):
584+
"""Get runtime configuration option value.
585+
586+
### Parameters
587+
588+
- **option**: the name of the configuration option.
589+
"""
590+
cmd = [self.CONFIG_CMD, 'GET', option]
591+
res = {}
592+
raw = self.redis.execute_command(*cmd)
593+
if raw:
594+
for kvs in raw:
595+
res[kvs[0]] = kvs[1]
596+
return res

test/test.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,15 @@ def testGet(self):
704704
self.assertEqual([['f1', 'some valid content dd2', 'f2', 'this is sample text ff2']], client.get('doc2'))
705705
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'))
706706

707+
def testConfig(self):
708+
client = self.getCleanClient('idx')
709+
self.assertTrue(client.config_set('TIMEOUT', '100'))
710+
self.assertFalse(client.config_set('TIMEOUT', "null"))
711+
res = client.config_get('*')
712+
self.assertEqual('100', res['TIMEOUT'])
713+
res = client.config_get('TIMEOUT')
714+
self.assertEqual('100', res['TIMEOUT'])
715+
707716
def testAggregations(self):
708717
conn = self.redis()
709718

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

775-
776784
if __name__ == '__main__':
777785

778786
unittest.main()

0 commit comments

Comments
 (0)