From 6ea64c15115484f3c0a8952d9c75d7252f23996d Mon Sep 17 00:00:00 2001 From: dengliming Date: Sat, 4 Apr 2020 14:55:27 +0800 Subject: [PATCH 1/5] Support FT.CONFIG command --- redisearch/client.py | 26 ++++++++++++++++++++++++++ test/test.py | 4 ++++ 2 files changed, 30 insertions(+) diff --git a/redisearch/client.py b/redisearch/client.py index f6a5317..2c7915b 100644 --- a/redisearch/client.py +++ b/redisearch/client.py @@ -119,6 +119,7 @@ class Client(object): DICT_DUMP_CMD = 'FT.DICTDUMP' GET_CMD = 'FT.GET' MGET_CMD = 'FT.MGET' + CONFIG_CMD = 'FT.CONFIG' NOOFFSETS = 'NOOFFSETS' @@ -507,3 +508,28 @@ def dict_dump(self, name): cmd = [self.DICT_DUMP_CMD, name] raw = self.redis.execute_command(*cmd) return raw + + def set_config(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 get_config(self, option): + """Get runtime configuration option value. + + ### Parameters + + - **option**: the name of the configuration option. + """ + cmd = [self.CONFIG_CMD, 'GET', option] + raw = self.redis.execute_command(*cmd) + if raw: + return raw[0][1] + return None \ No newline at end of file diff --git a/test/test.py b/test/test.py index 3a72be6..74a4aaf 100644 --- a/test/test.py +++ b/test/test.py @@ -658,6 +658,10 @@ 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.set_config('TIMEOUT', '100')) + self.assertEqual('100', client.get_config('TIMEOUT')) if __name__ == '__main__': From 77adcdd7361f3591371a85fd21277435adf01ef1 Mon Sep 17 00:00:00 2001 From: dengliming Date: Sat, 4 Apr 2020 14:59:21 +0800 Subject: [PATCH 2/5] Remove unnecessary code --- redisearch/client.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/redisearch/client.py b/redisearch/client.py index 2c7915b..81eba8d 100644 --- a/redisearch/client.py +++ b/redisearch/client.py @@ -531,5 +531,4 @@ def get_config(self, option): cmd = [self.CONFIG_CMD, 'GET', option] raw = self.redis.execute_command(*cmd) if raw: - return raw[0][1] - return None \ No newline at end of file + return raw[0][1] \ No newline at end of file From 67bc9080c40352c8444561baebe918ffd735e621 Mon Sep 17 00:00:00 2001 From: dengliming Date: Sun, 5 Apr 2020 04:40:02 +0800 Subject: [PATCH 3/5] Update get_config return type --- redisearch/client.py | 5 ++++- test/test.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/redisearch/client.py b/redisearch/client.py index 81eba8d..6e63573 100644 --- a/redisearch/client.py +++ b/redisearch/client.py @@ -529,6 +529,9 @@ def get_config(self, option): - **option**: the name of the configuration option. """ cmd = [self.CONFIG_CMD, 'GET', option] + res = {} raw = self.redis.execute_command(*cmd) if raw: - return raw[0][1] \ No newline at end of file + for kvs in raw: + res[kvs[0]] = kvs[1] + return res diff --git a/test/test.py b/test/test.py index 74a4aaf..5678e18 100644 --- a/test/test.py +++ b/test/test.py @@ -661,7 +661,10 @@ def testGet(self): def testConfig(self): client = self.getCleanClient('idx') self.assertTrue(client.set_config('TIMEOUT', '100')) - self.assertEqual('100', client.get_config('TIMEOUT')) + res = client.get_config('*') + self.assertEqual('100', res['TIMEOUT']) + res = client.get_config('TIMEOUT') + self.assertEqual('100', res['TIMEOUT']) if __name__ == '__main__': From f410f5fd18d3802ff4cccb929b96aa0b706c9b47 Mon Sep 17 00:00:00 2001 From: dengliming Date: Sun, 5 Apr 2020 18:52:25 +0800 Subject: [PATCH 4/5] Add negative tests --- test/test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test.py b/test/test.py index 5678e18..5b398fd 100644 --- a/test/test.py +++ b/test/test.py @@ -661,6 +661,7 @@ def testGet(self): def testConfig(self): client = self.getCleanClient('idx') self.assertTrue(client.set_config('TIMEOUT', '100')) + self.assertFalse(client.set_config('TIMEOUT', "null")) res = client.get_config('*') self.assertEqual('100', res['TIMEOUT']) res = client.get_config('TIMEOUT') From a73dd3c11f8c921f9c9ee00349ebd0962b538233 Mon Sep 17 00:00:00 2001 From: dengliming Date: Sun, 5 Apr 2020 23:19:30 +0800 Subject: [PATCH 5/5] Rename config method --- redisearch/client.py | 4 ++-- test/test.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/redisearch/client.py b/redisearch/client.py index 6e63573..8f9b5f7 100644 --- a/redisearch/client.py +++ b/redisearch/client.py @@ -509,7 +509,7 @@ def dict_dump(self, name): raw = self.redis.execute_command(*cmd) return raw - def set_config(self, option, value): + def config_set(self, option, value): """Set runtime configuration option. ### Parameters @@ -521,7 +521,7 @@ def set_config(self, option, value): raw = self.redis.execute_command(*cmd) return raw == 'OK' - def get_config(self, option): + def config_get(self, option): """Get runtime configuration option value. ### Parameters diff --git a/test/test.py b/test/test.py index 5b398fd..b8a91a2 100644 --- a/test/test.py +++ b/test/test.py @@ -660,11 +660,11 @@ def testGet(self): def testConfig(self): client = self.getCleanClient('idx') - self.assertTrue(client.set_config('TIMEOUT', '100')) - self.assertFalse(client.set_config('TIMEOUT', "null")) - res = client.get_config('*') + 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.get_config('TIMEOUT') + res = client.config_get('TIMEOUT') self.assertEqual('100', res['TIMEOUT']) if __name__ == '__main__':