-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add support for Redis 7 functions #1998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
04eb451
add function support
dvora-h 807b783
linters
dvora-h 3d0c25a
test fcall
dvora-h e845164
decode reponses for unstable_r
dvora-h f4a1a25
linters
dvora-h 8977673
fix evalsho_ro test
dvora-h 5cc6ace
fix eval_ro test
dvora-h 5531b54
add response callbaks
dvora-h d7309b8
Merge branch 'master' into add-functions
dvora-h 4d4ff34
linters
dvora-h File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import pytest | ||
|
||
from redis.exceptions import ResponseError | ||
|
||
function = "redis.register_function('myfunc', function(keys, args) return args[1] end)" | ||
function2 = "redis.register_function('hello', function() return 'Hello World' end)" | ||
set_function = "redis.register_function('set', function(keys, args) \ | ||
return redis.call('SET', keys[1], args[1]) end)" | ||
get_function = "redis.register_function('get', function(keys, args) \ | ||
return redis.call('GET', keys[1]) end)" | ||
|
||
|
||
@pytest.mark.onlynoncluster | ||
# @skip_if_server_version_lt("7.0.0") turn on after redis 7 release | ||
class TestFunction: | ||
@pytest.fixture(autouse=True) | ||
def reset_functions(self, unstable_r): | ||
unstable_r.function_flush() | ||
|
||
def test_function_load(self, unstable_r): | ||
assert unstable_r.function_load("Lua", "mylib", function) | ||
assert unstable_r.function_load("Lua", "mylib", function, replace=True) | ||
with pytest.raises(ResponseError): | ||
unstable_r.function_load("Lua", "mylib", function) | ||
with pytest.raises(ResponseError): | ||
unstable_r.function_load("Lua", "mylib2", function) | ||
|
||
def test_function_delete(self, unstable_r): | ||
unstable_r.function_load("Lua", "mylib", set_function) | ||
with pytest.raises(ResponseError): | ||
unstable_r.function_load("Lua", "mylib", set_function) | ||
assert unstable_r.fcall("set", 1, "foo", "bar") == "OK" | ||
assert unstable_r.function_delete("mylib") | ||
with pytest.raises(ResponseError): | ||
unstable_r.fcall("set", 1, "foo", "bar") | ||
assert unstable_r.function_load("Lua", "mylib", set_function) | ||
|
||
def test_function_flush(self, unstable_r): | ||
unstable_r.function_load("Lua", "mylib", function) | ||
assert unstable_r.fcall("myfunc", 0, "hello") == "hello" | ||
assert unstable_r.function_flush() | ||
with pytest.raises(ResponseError): | ||
unstable_r.fcall("myfunc", 0, "hello") | ||
with pytest.raises(ResponseError): | ||
unstable_r.function_flush("ABC") | ||
|
||
def test_function_list(self, unstable_r): | ||
unstable_r.function_load("Lua", "mylib", function) | ||
res = [ | ||
[ | ||
"library_name", | ||
"mylib", | ||
"engine", | ||
"LUA", | ||
"description", | ||
None, | ||
"functions", | ||
[["name", "myfunc", "description", None]], | ||
], | ||
] | ||
assert unstable_r.function_list() == res | ||
assert unstable_r.function_list(library="*lib") == res | ||
assert unstable_r.function_list(withcode=True)[0][9] == function | ||
|
||
def test_fcall(self, unstable_r): | ||
unstable_r.function_load("Lua", "mylib", set_function) | ||
unstable_r.function_load("Lua", "mylib2", get_function) | ||
assert unstable_r.fcall("set", 1, "foo", "bar") == "OK" | ||
assert unstable_r.fcall("get", 1, "foo") == "bar" | ||
with pytest.raises(ResponseError): | ||
unstable_r.fcall("myfunc", 0, "hello") | ||
|
||
def test_fcall_ro(self, unstable_r): | ||
unstable_r.function_load("Lua", "mylib", function) | ||
assert unstable_r.fcall_ro("myfunc", 0, "hello") == "hello" | ||
unstable_r.function_load("Lua", "mylib2", set_function) | ||
with pytest.raises(ResponseError): | ||
unstable_r.fcall_ro("set", 1, "foo", "bar") | ||
|
||
def test_function_dump_restore(self, unstable_r): | ||
unstable_r.function_load("Lua", "mylib", set_function) | ||
payload = unstable_r.function_dump() | ||
assert unstable_r.fcall("set", 1, "foo", "bar") == "OK" | ||
unstable_r.function_delete("mylib") | ||
with pytest.raises(ResponseError): | ||
unstable_r.fcall("set", 1, "foo", "bar") | ||
assert unstable_r.function_restore(payload) | ||
assert unstable_r.fcall("set", 1, "foo", "bar") == "OK" | ||
unstable_r.function_load("Lua", "mylib2", get_function) | ||
assert unstable_r.fcall("get", 1, "foo") == "bar" | ||
unstable_r.function_delete("mylib") | ||
assert unstable_r.function_restore(payload, "FLUSH") | ||
with pytest.raises(ResponseError): | ||
unstable_r.fcall("get", 1, "foo") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.