Skip to content

Commit

Permalink
Add comments for new API
Browse files Browse the repository at this point in the history
Signed-off-by: hwware <[email protected]>
  • Loading branch information
hwware committed Nov 5, 2024
1 parent ae25870 commit 47b7379
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
44 changes: 27 additions & 17 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -2254,6 +2254,33 @@ int moduleIsModuleCommand(void *module_handle, struct serverCommand *cmd) {
return (cp->module == module_handle);
}

/* ValkeyModule_UpdateRuntimeArgs can be used to update the values of module->loadmod
* so that the updated values can be saved into conf file once 'config rewrite' command
* is called
* One example can be found in file modules/moduleparameter.c
*
* Returns:
* - VALKEYMODULE_OK on successfully updating.
* - VALKEYMODULE_ERR on failure.
*/
int VM_UpdateRuntimeArgs(ValkeyModuleCtx *ctx, int argc, ValkeyModuleString **argv) {
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]);
}
return VALKEYMODULE_OK;
}

/* --------------------------------------------------------------------------
* ## Module information and time measurement
* -------------------------------------------------------------------------- */
Expand Down Expand Up @@ -3042,23 +3069,6 @@ client *moduleGetReplyClient(ValkeyModuleCtx *ctx) {
}
}

int VM_UpdateRuntimeArgs(ValkeyModuleCtx *ctx, int argc, ValkeyModuleString **argv) {
client *c = moduleGetReplyClient(ctx);
if (c == NULL) return VALKEYMODULE_OK;
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;
}

/* Send an integer reply to the client, with the specified `long long` value.
* The function always returns VALKEYMODULE_OK. */
int VM_ReplyWithLongLong(ValkeyModuleCtx *ctx, long long ll) {
Expand Down
3 changes: 0 additions & 3 deletions tests/unit/moduleapi/moduleconfigs.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,3 @@ start_server {tags {"modules"}} {
string match "40 50 60 70" [lmap x [r module list] {dict get $x args}]
}
}



0 comments on commit 47b7379

Please sign in to comment.