diff --git a/redisearch/client.py b/redisearch/client.py index 37146e6..21e6d8a 100644 --- a/redisearch/client.py +++ b/redisearch/client.py @@ -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' @@ -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 diff --git a/test/test.py b/test/test.py index f49534e..5942db3 100644 --- a/test/test.py +++ b/test/test.py @@ -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() @@ -772,7 +781,6 @@ def testAggregations(self): self.assertEqual(b'RediSearch', res[23]) self.assertEqual(2, len(res[25])) - if __name__ == '__main__': unittest.main()