Skip to content

Commit 1f046ac

Browse files
authored
Add support for MODULE LOADEX (#2146)
1 parent a696fe5 commit 1f046ac

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

redis/commands/core.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5592,6 +5592,27 @@ def module_load(self, path, *args) -> ResponseT:
55925592
"""
55935593
return self.execute_command("MODULE LOAD", path, *args)
55945594

5595+
def module_loadex(
5596+
self,
5597+
path: str,
5598+
options: Optional[List[str]] = None,
5599+
args: Optional[List[str]] = None,
5600+
) -> ResponseT:
5601+
"""
5602+
Loads a module from a dynamic library at runtime with configuration directives.
5603+
5604+
For more information see https://redis.io/commands/module-loadex
5605+
"""
5606+
pieces = []
5607+
if options is not None:
5608+
pieces.append("CONFIG")
5609+
pieces.extend(options)
5610+
if args is not None:
5611+
pieces.append("ARGS")
5612+
pieces.extend(args)
5613+
5614+
return self.execute_command("MODULE LOADEX", path, *pieces)
5615+
55955616
def module_unload(self, name) -> ResponseT:
55965617
"""
55975618
Unloads the module ``name``.

tests/test_commands.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4513,6 +4513,18 @@ def test_module(self, r):
45134513
r.module_load("/some/fake/path", "arg1", "arg2", "arg3", "arg4")
45144514
assert "Error loading the extension." in str(excinfo.value)
45154515

4516+
@pytest.mark.onlynoncluster
4517+
@skip_if_server_version_lt("7.0.0")
4518+
@skip_if_redis_enterprise()
4519+
def test_module_loadex(self, r: redis.Redis):
4520+
with pytest.raises(redis.exceptions.ModuleError) as excinfo:
4521+
r.module_loadex("/some/fake/path")
4522+
assert "Error loading the extension." in str(excinfo.value)
4523+
4524+
with pytest.raises(redis.exceptions.ModuleError) as excinfo:
4525+
r.module_loadex("/some/fake/path", ["name", "value"], ["arg1", "arg2"])
4526+
assert "Error loading the extension." in str(excinfo.value)
4527+
45164528
@skip_if_server_version_lt("2.6.0")
45174529
def test_restore(self, r):
45184530

0 commit comments

Comments
 (0)