Modules: block ok keys: improve example.
This commit is contained in:
parent
66f55bc5c1
commit
37bf3e18cb
@ -244,12 +244,20 @@ int HelloTypeBRange_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv,
|
|||||||
return RedisModule_ReplyWithError(ctx,REDISMODULE_ERRORMSG_WRONGTYPE);
|
return RedisModule_ReplyWithError(ctx,REDISMODULE_ERRORMSG_WRONGTYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Parse the timeout before even trying to serve the client synchronously,
|
||||||
|
* so that we always fail ASAP on syntax errors. */
|
||||||
long long timeout;
|
long long timeout;
|
||||||
if (RedisModule_StringToLongLong(argv[4],&timeout) != REDISMODULE_OK) {
|
if (RedisModule_StringToLongLong(argv[4],&timeout) != REDISMODULE_OK) {
|
||||||
return RedisModule_ReplyWithError(ctx,
|
return RedisModule_ReplyWithError(ctx,
|
||||||
"ERR invalid timeout parameter");
|
"ERR invalid timeout parameter");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Can we serve the reply synchronously? */
|
||||||
|
if (type != REDISMODULE_KEYTYPE_EMPTY) {
|
||||||
|
return HelloTypeRange_RedisCommand(ctx,argv,argc-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Otherwise let's block on the key. */
|
||||||
void *privdata = RedisModule_Alloc(100);
|
void *privdata = RedisModule_Alloc(100);
|
||||||
RedisModule_BlockClientOnKeys(ctx,HelloBlock_Reply,HelloBlock_Timeout,HelloBlock_FreeData,timeout,argv+1,1,privdata);
|
RedisModule_BlockClientOnKeys(ctx,HelloBlock_Reply,HelloBlock_Timeout,HelloBlock_FreeData,timeout,argv+1,1,privdata);
|
||||||
return REDISMODULE_OK;
|
return REDISMODULE_OK;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user