From 0e87c6f79cd8ce2da68f2262144b1fd982d8cea2 Mon Sep 17 00:00:00 2001 From: "bodong.ybd" Date: Mon, 7 Aug 2023 20:16:28 +0800 Subject: [PATCH] Support function load command --- cts.json | 13 +++++++++++++ redis_compatibility_test.py | 23 ++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/cts.json b/cts.json index 822c79a..c3e7950 100644 --- a/cts.json +++ b/cts.json @@ -5314,5 +5314,18 @@ "True" ], "since": "2.2.0" + }, + { + "name": "function load command", + "command": [ + "function flush", + "function load \"#!lua name=mylib \n redis.register_function('myfunc', function(keys, args) return args[1] end)\"" + ], + "result": [ + "OK", + "mylib" + ], + "since": "7.0.0", + "command_split": true } ] diff --git a/redis_compatibility_test.py b/redis_compatibility_test.py index 310c4c5..8085cf7 100644 --- a/redis_compatibility_test.py +++ b/redis_compatibility_test.py @@ -130,6 +130,23 @@ def trans_cmd(test, cmd): array.append(ord(cmd[i])) i += 1 return bytes(array) + elif 'command_split' in test: + # split command by "" + # input: 'hello "world of python" example' + # output: ['hello', 'world of python', 'example'] + parts = [] + in_quote = False + current_part = '' + for char in cmd: + if char == '"': + in_quote = not in_quote + elif char == ' ' and not in_quote: + parts.append(current_part) + current_part = '' + else: + current_part += char + parts.append(current_part) + return parts else: return cmd @@ -156,7 +173,11 @@ def run_test(test): trans_result_to_bytes(result) try: for idx, cmd in enumerate(command): - ret = trans_result_to_bytes(r.execute_command(trans_cmd(test, cmd))) + tcmd = trans_cmd(test, cmd) + if (isinstance(tcmd, list)): + ret = trans_result_to_bytes(r.execute_command(*trans_cmd(test, cmd))) + else: + ret = trans_result_to_bytes(r.execute_command(trans_cmd(test, cmd))) if result[idx] != ret: test_failed(g_results[since], name, f"expected: {result[idx]}, result: {ret}") return