Skip to content

Commit

Permalink
update UpdateRuntimeArgs function logic and test case codes
Browse files Browse the repository at this point in the history
  • Loading branch information
hwware committed Nov 22, 2024
1 parent aa2ba36 commit 158477e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
13 changes: 5 additions & 8 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -2264,19 +2264,16 @@ int moduleIsModuleCommand(void *module_handle, struct serverCommand *cmd) {
* - VALKEYMODULE_ERR on failure.
*/
int VM_UpdateRuntimeArgs(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
if (!ctx->module->onload) {
return VALKEYMODULE_ERR;
}
struct moduleLoadQueueEntry *loadmod = ctx->module->loadmod;
for (int i = 0; i < loadmod->argc; i++) {
decrRefCount(loadmod->argv[i]);
}
zfree(loadmod->argv);
loadmod->argv = argc ? zmalloc(sizeof(robj *) * argc) : NULL;
loadmod->argc = argc;
for (int i = 0; i < argc; i++) {
loadmod->argv[i] = argv[i];
incrRefCount(loadmod->argv[i]);
loadmod->argv = argc - 1 ? zmalloc(sizeof(robj *) * (argc - 1)) : NULL;
loadmod->argc = argc - 1;
for (int i = 1; i < argc; i++) {
loadmod->argv[i - 1] = argv[i];
incrRefCount(loadmod->argv[i - 1]);
}
return VALKEYMODULE_OK;
}
Expand Down
4 changes: 3 additions & 1 deletion tests/modules/moduleparameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

int test_module_update_parameter(ValkeyModuleCtx *ctx,
ValkeyModuleString **argv, int argc) {
return ValkeyModule_UpdateRuntimeArgs(ctx, argv, argc);

ValkeyModule_UpdateRuntimeArgs(ctx, argv, argc);
return ValkeyModule_ReplyWithSimpleString(ctx, "OK");
}

int ValkeyModule_OnLoad(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/moduleapi/moduleconfigs.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ start_server {tags {"modules"}} {
set modulename [lmap x [r module list] {dict get $x name}]
assert_not_equal [lsearch $modulename moduleparameter] -1
assert_equal "{10 20 30}" [lmap x [r module list] {dict get $x args}]
r testmoduleparameter.update.parameter 40 50 60 70
assert_equal OK [r testmoduleparameter.update.parameter 40 50 60 70]
assert_equal "{40 50 60 70}" [lmap x [r module list] {dict get $x args}]
}
}

0 comments on commit 158477e

Please sign in to comment.