Skip to content

Commit

Permalink
Update implementation for API VM_UpdateRunTimeArgs
Browse files Browse the repository at this point in the history
Signed-off-by: hwware <[email protected]>
  • Loading branch information
hwware committed Oct 31, 2024
1 parent 811b9cc commit b4d698d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
16 changes: 12 additions & 4 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -3042,12 +3042,20 @@ client *moduleGetReplyClient(ValkeyModuleCtx *ctx) {
}
}

int VM_UpdateRunTimeArgs(ValkeyModuleCtx *ctx, int index, char *value) {
int VM_UpdateRunTimeArgs(ValkeyModuleCtx *ctx, int argc, ValkeyModuleString **argv) {
client *c = moduleGetReplyClient(ctx);
if (c == NULL) return VALKEYMODULE_OK;

ValkeyModuleString *o = createStringObject(value, strlen(value));
ctx->module->loadmod->argv[index] = o;
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]);
}
return VALKEYMODULE_OK;
}

Expand Down
2 changes: 1 addition & 1 deletion src/valkeymodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ VALKEYMODULE_API void (*ValkeyModule_SetModuleAttribs)(ValkeyModuleCtx *ctx, con
VALKEYMODULE_ATTR;
VALKEYMODULE_API int (*ValkeyModule_IsModuleNameBusy)(const char *name) VALKEYMODULE_ATTR;
VALKEYMODULE_API int (*ValkeyModule_WrongArity)(ValkeyModuleCtx *ctx) VALKEYMODULE_ATTR;
VALKEYMODULE_API int (*ValkeyModule_UpdateRunTimeArgs)(ValkeyModuleCtx *ctx, int index, char *value) VALKEYMODULE_ATTR;
VALKEYMODULE_API int (*ValkeyModule_UpdateRunTimeArgs)(ValkeyModuleCtx *ctx, int argc, ValkeyModuleString **argv) VALKEYMODULE_ATTR;
VALKEYMODULE_API int (*ValkeyModule_ReplyWithLongLong)(ValkeyModuleCtx *ctx, long long ll) VALKEYMODULE_ATTR;
VALKEYMODULE_API int (*ValkeyModule_GetSelectedDb)(ValkeyModuleCtx *ctx) VALKEYMODULE_ATTR;
VALKEYMODULE_API int (*ValkeyModule_SelectDb)(ValkeyModuleCtx *ctx, int newid) VALKEYMODULE_ATTR;
Expand Down
7 changes: 2 additions & 5 deletions tests/modules/moduleparameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
#include <string.h>

int GET_HELLO(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
VALKEYMODULE_NOT_USED(argv);
VALKEYMODULE_NOT_USED(argc);

ValkeyModule_UpdateRunTimeArgs(ctx, 0, "99");
return ValkeyModule_ReplyWithSimpleString(ctx, "Module runtime args test");
ValkeyModule_UpdateRunTimeArgs(ctx, argc, argv);
return ValkeyModule_ReplyWithSimpleString(ctx, "Module runtime args test");
}

int ValkeyModule_OnLoad(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/moduleapi/moduleconfigs.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ start_server {tags {"modules"}} {
set modulename [lmap x [r module list] {dict get $x name}]
assert_not_equal [lsearch $modulename myhello] -1
string match "10 20 30" [lmap x [r module list] {dict get $x args}]
r hello.hi
string match "99 20 30" [lmap x [r module list] {dict get $x args}]
r hello.hi 40 50 60 70
string match "40 50 60 70" [lmap x [r module list] {dict get $x args}]
}
}

Expand Down

0 comments on commit b4d698d

Please sign in to comment.