Skip to content

Commit c84ebca

Browse files
Add support for MustObeyClient Module API
Signed-off-by: KarthikSubbarao <[email protected]>
1 parent 2d0b8e3 commit c84ebca

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/module.c

+9
Original file line numberDiff line numberDiff line change
@@ -3719,6 +3719,14 @@ ValkeyModuleString *VM_GetClientUserNameById(ValkeyModuleCtx *ctx, uint64_t id)
37193719
return str;
37203720
}
37213721

3722+
/* Returns 1 if commands are arriving from the primary client or AOF client
3723+
* and should never be rejected.
3724+
* Returns 0 otherwise (and also if ctx or if the client is NULL). */
3725+
int VM_MustObeyClient(ValkeyModuleCtx *ctx) {
3726+
if (!ctx || !ctx->client) return 0;
3727+
return mustObeyClient(ctx->client);
3728+
}
3729+
37223730
/* This is a helper for VM_GetClientInfoById() and other functions: given
37233731
* a client, it populates the client info structure with the appropriate
37243732
* fields depending on the version provided. If the version is not valid
@@ -13839,6 +13847,7 @@ void moduleRegisterCoreAPI(void) {
1383913847
REGISTER_API(ChannelAtPosWithFlags);
1384013848
REGISTER_API(GetClientId);
1384113849
REGISTER_API(GetClientUserNameById);
13850+
REGISTER_API(MustObeyClient);
1384213851
REGISTER_API(GetContextFlags);
1384313852
REGISTER_API(AvoidReplicaTraffic);
1384413853
REGISTER_API(PoolAlloc);

src/valkeymodule.h

+1
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,7 @@ VALKEYMODULE_API int (*ValkeyModule_GetClientInfoById)(void *ci, uint64_t id) VA
13211321
VALKEYMODULE_API ValkeyModuleString *(*ValkeyModule_GetClientNameById)(ValkeyModuleCtx *ctx,
13221322
uint64_t id)VALKEYMODULE_ATTR;
13231323
VALKEYMODULE_API int (*ValkeyModule_SetClientNameById)(uint64_t id, ValkeyModuleString *name) VALKEYMODULE_ATTR;
1324+
VALKEYMODULE_API int *(*ValkeyModule_MustObeyClient)(ValkeyModuleCtx *ctx)VALKEYMODULE_ATTR;
13241325
VALKEYMODULE_API int (*ValkeyModule_PublishMessage)(ValkeyModuleCtx *ctx,
13251326
ValkeyModuleString *channel,
13261327
ValkeyModuleString *message) VALKEYMODULE_ATTR;

0 commit comments

Comments
 (0)