Skip to content

Redis modules and blocking commands #2605

Open
@v5v6

Description

@v5v6

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;

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions