Skip to content

Commit

Permalink
Add support for MustObeyClient Module API
Browse files Browse the repository at this point in the history
Signed-off-by: KarthikSubbarao <[email protected]>
  • Loading branch information
KarthikSubbarao committed Jan 18, 2025
1 parent 2d0b8e3 commit 2ead724
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -3719,6 +3719,14 @@ ValkeyModuleString *VM_GetClientUserNameById(ValkeyModuleCtx *ctx, uint64_t id)
return str;
}

/* Returns 1 if commands are arriving from the primary client or AOF client
* and should never be rejected.
* Returns 0 otherwise (and also if ctx or if the client is NULL). */
int VM_MustObeyClient(ValkeyModuleCtx *ctx) {
if (!ctx || !ctx->client) return 0;
return mustObeyClient(ctx->client);
}

/* This is a helper for VM_GetClientInfoById() and other functions: given
* a client, it populates the client info structure with the appropriate
* fields depending on the version provided. If the version is not valid
Expand Down Expand Up @@ -13839,6 +13847,7 @@ void moduleRegisterCoreAPI(void) {
REGISTER_API(ChannelAtPosWithFlags);
REGISTER_API(GetClientId);
REGISTER_API(GetClientUserNameById);
REGISTER_API(MustObeyClient);
REGISTER_API(GetContextFlags);
REGISTER_API(AvoidReplicaTraffic);
REGISTER_API(PoolAlloc);
Expand Down
1 change: 1 addition & 0 deletions src/valkeymodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,7 @@ VALKEYMODULE_API int (*ValkeyModule_GetClientInfoById)(void *ci, uint64_t id) VA
VALKEYMODULE_API ValkeyModuleString *(*ValkeyModule_GetClientNameById)(ValkeyModuleCtx *ctx,
uint64_t id)VALKEYMODULE_ATTR;
VALKEYMODULE_API int (*ValkeyModule_SetClientNameById)(uint64_t id, ValkeyModuleString *name) VALKEYMODULE_ATTR;
VALKEYMODULE_API int *(*ValkeyModule_MustObeyClient)(ValkeyModuleCtx *ctx)VALKEYMODULE_ATTR;
VALKEYMODULE_API int (*ValkeyModule_PublishMessage)(ValkeyModuleCtx *ctx,
ValkeyModuleString *channel,
ValkeyModuleString *message) VALKEYMODULE_ATTR;
Expand Down

0 comments on commit 2ead724

Please sign in to comment.