Skip to content

Commit

Permalink
Add API UpdateRunTimeArgs
Browse files Browse the repository at this point in the history
  • Loading branch information
hwware committed Oct 17, 2024
1 parent 5c63d6d commit 043e22e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
17 changes: 6 additions & 11 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -3042,18 +3042,13 @@ client *moduleGetReplyClient(ValkeyModuleCtx *ctx) {
}
}

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

ValkeyModuleRunTimeArgs *args = zmalloc(sizeof(struct ValkeyModuleRunTimeArgs));
int argc = ctx->module->loadmod->argc;
args->argv = argc ? zmalloc(sizeof(robj *) * argc) : NULL;
args->argc = argc;
for (int i = 0; i < argc; i++) {
args->argv[i] = (char *)ctx->module->loadmod->argv[i]->ptr;
}
return args;
ValkeyModuleString *o = createStringObject(value, strlen(value));
ctx->module->loadmod->argv[index] = o;
return VALKEYMODULE_OK;
}

/* Send an integer reply to the client, with the specified `long long` value.
Expand Down Expand Up @@ -13574,7 +13569,7 @@ void moduleRegisterCoreAPI(void) {
REGISTER_API(SetModuleAttribs);
REGISTER_API(IsModuleNameBusy);
REGISTER_API(WrongArity);
REGISTER_API(GetRunTimeArgs);
REGISTER_API(UpdateRunTimeArgs);
REGISTER_API(ReplyWithLongLong);
REGISTER_API(ReplyWithError);
REGISTER_API(ReplyWithErrorFormat);
Expand Down
3 changes: 1 addition & 2 deletions src/redismodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@
#define RedisModuleCommandInfo ValkeyModuleCommandInfo
#define RedisModuleCommandKeySpec ValkeyModuleCommandKeySpec
#define RedisModuleCommandHistoryEntry ValkeyModuleCommandHistoryEntry
#define RedisModuleRunTimeArgs ValkeyModuleRunTimeArgs

/* RedisModule APIs */
#define RedisModule_OnLoad ValkeyModule_OnLoad
Expand All @@ -358,7 +357,7 @@
#define RedisModule_SetModuleAttribs ValkeyModule_SetModuleAttribs
#define RedisModule_IsModuleNameBusy ValkeyModule_IsModuleNameBusy
#define RedisModule_WrongArity ValkeyModule_WrongArity
#define RedisModule_GetRunTimeArgs ValkeyModule_GetRunTimeArgs
#define RedisModule_UpdateRunTimeArgs ValkeyModule_UpdateRunTimeArgs
#define RedisModule_ReplyWithLongLong ValkeyModule_ReplyWithLongLong
#define RedisModule_GetSelectedDb ValkeyModule_GetSelectedDb
#define RedisModule_SelectDb ValkeyModule_SelectDb
Expand Down
9 changes: 2 additions & 7 deletions src/valkeymodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,6 @@ typedef long long ustime_t;
#define VALKEYMODULE_CONFIG_MEMORY (1ULL << 7) /* Indicates if this value can be set as a memory value */
#define VALKEYMODULE_CONFIG_BITFLAGS (1ULL << 8) /* Indicates if this value can be set as a multiple enum values */

typedef struct ValkeyModuleRunTimeArgs {
int argc;
char **argv;
} ValkeyModuleRunTimeArgs;

/* StreamID type. */
typedef struct ValkeyModuleStreamID {
uint64_t ms;
Expand Down Expand Up @@ -972,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 struct ValkeyModuleRunTimeArgs *(*ValkeyModule_GetRunTimeArgs)(ValkeyModuleCtx *ctx)VALKEYMODULE_ATTR;
VALKEYMODULE_API int (*ValkeyModule_UpdateRunTimeArgs)(ValkeyModuleCtx *ctx, int index, char *value)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 Expand Up @@ -1679,7 +1674,7 @@ static int ValkeyModule_Init(ValkeyModuleCtx *ctx, const char *name, int ver, in
VALKEYMODULE_GET_API(SetModuleAttribs);
VALKEYMODULE_GET_API(IsModuleNameBusy);
VALKEYMODULE_GET_API(WrongArity);
VALKEYMODULE_GET_API(GetRunTimeArgs);
VALKEYMODULE_GET_API(UpdateRunTimeArgs);
VALKEYMODULE_GET_API(ReplyWithLongLong);
VALKEYMODULE_GET_API(ReplyWithError);
VALKEYMODULE_GET_API(ReplyWithErrorFormat);
Expand Down

0 comments on commit 043e22e

Please sign in to comment.