Skip to content

Commit

Permalink
Merge pull request #11 from tair-opensource/feature-function-load
Browse files Browse the repository at this point in the history
Support function load command
  • Loading branch information
yangbodong22011 authored Aug 8, 2023
2 parents 758ac48 + 0e87c6f commit 37e7861
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
13 changes: 13 additions & 0 deletions cts.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
23 changes: 22 additions & 1 deletion redis_compatibility_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 37e7861

Please sign in to comment.