Skip to content

Commit ac13fd6

Browse files
committed
Add support for MODULE LOADEX
1 parent cb91eed commit ac13fd6

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

Diff for: redis/commands/core.py

+21
Original file line numberDiff line numberDiff line change
@@ -5574,6 +5574,27 @@ def module_load(self, path, *args) -> ResponseT:
55745574
"""
55755575
return self.execute_command("MODULE LOAD", path, *args)
55765576

5577+
def module_loadex(
5578+
self,
5579+
path: str,
5580+
options: Optional[List[str]] = None,
5581+
args: Optional[List[str]] = None,
5582+
) -> ResponseT:
5583+
"""
5584+
Loads a module from a dynamic library at runtime with configuration directives.
5585+
5586+
For more information see https://redis.io/commands/module-loadex
5587+
"""
5588+
pieces = []
5589+
if options is not None:
5590+
pieces.append("CONFIG")
5591+
pieces.extend(options)
5592+
if args is not None:
5593+
pieces.append("ARGS")
5594+
pieces.extend(args)
5595+
5596+
return self.execute_command("MODULE LOADEX", path, *pieces)
5597+
55775598
def module_unload(self, name) -> ResponseT:
55785599
"""
55795600
Unloads the module ``name``.

Diff for: tests/test_commands.py

+12
Original file line numberDiff line numberDiff line change
@@ -4480,6 +4480,18 @@ def test_module(self, r):
44804480
r.module_load("/some/fake/path", "arg1", "arg2", "arg3", "arg4")
44814481
assert "Error loading the extension." in str(excinfo.value)
44824482

4483+
@pytest.mark.onlynoncluster
4484+
@skip_if_server_version_lt("7.0.0")
4485+
@skip_if_redis_enterprise()
4486+
def test_module_loadex(self, r: redis.Redis):
4487+
with pytest.raises(redis.exceptions.ModuleError) as excinfo:
4488+
r.module_loadex("/some/fake/path")
4489+
assert "Error loading the extension." in str(excinfo.value)
4490+
4491+
with pytest.raises(redis.exceptions.ModuleError) as excinfo:
4492+
r.module_loadex("/some/fake/path", ["name", "value"], ["arg1", "arg2"])
4493+
assert "Error loading the extension." in str(excinfo.value)
4494+
44834495
@skip_if_server_version_lt("2.6.0")
44844496
def test_restore(self, r):
44854497

0 commit comments

Comments
 (0)