redis-doc icon indicating copy to clipboard operation
redis-doc copied to clipboard

Redis modules and blocking commands

Open v5v6 opened this issue 9 months ago • 0 comments

In the link https://redis.io/docs/reference/modules/modules-blocking-ops/ I found the latest example code is not correct, as RedisModule_IsBlockedReplyRequest should be used the general_func other than in the Example_RedisCommand function. BRs,

int general_func(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { if (RedisModule_IsBlockedReplyRequest(ctx)) { long *mynumber = RedisModule_GetBlockedClientPrivateData(ctx); return RedisModule_ReplyWithLongLong(ctx,mynumber); } else if (RedisModule_IsBlockedTimeoutRequest(ctx)) { return RedisModule_ReplyWithNull(ctx); } }

int Example_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {

RedisModuleBlockedClient *bc =
    RedisModule_BlockClient(ctx,general_func,general_func,NULL,0);

pthread_t tid;
if (pthread_create(&tid,NULL,threadmain,bc) != 0) {
    RedisModule_AbortBlock(bc);
    RedisModule_ReplyWithError(ctx,"Sorry can't create a thread");
}

return REDISMODULE_OK;

}

v5v6 avatar Nov 24 '23 08:11 v5v6