diff --git a/src/module.c b/src/module.c index 75dcd81cd6..9f4cbc8c48 100644 --- a/src/module.c +++ b/src/module.c @@ -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 @@ -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); diff --git a/src/valkeymodule.h b/src/valkeymodule.h index c501b373fd..de192d66ed 100644 --- a/src/valkeymodule.h +++ b/src/valkeymodule.h @@ -1317,6 +1317,7 @@ VALKEYMODULE_API void (*ValkeyModule_ChannelAtPosWithFlags)(ValkeyModuleCtx *ctx VALKEYMODULE_API unsigned long long (*ValkeyModule_GetClientId)(ValkeyModuleCtx *ctx) VALKEYMODULE_ATTR; VALKEYMODULE_API ValkeyModuleString *(*ValkeyModule_GetClientUserNameById)(ValkeyModuleCtx *ctx, uint64_t id)VALKEYMODULE_ATTR; +VALKEYMODULE_API int *(*ValkeyModule_MustObeyClient)(ValkeyModuleCtx *ctx) VALKEYMODULE_ATTR; VALKEYMODULE_API int (*ValkeyModule_GetClientInfoById)(void *ci, uint64_t id) VALKEYMODULE_ATTR; VALKEYMODULE_API ValkeyModuleString *(*ValkeyModule_GetClientNameById)(ValkeyModuleCtx *ctx, uint64_t id)VALKEYMODULE_ATTR;