Modules: fixes to the blocking commands API: examples now works.
This commit is contained in:
parent
f156038db8
commit
34599691b3
12
src/module.c
12
src/module.c
@ -3115,7 +3115,7 @@ RedisModuleBlockedClient *RM_BlockClient(RedisModuleCtx *ctx, RedisModuleCmdFunc
|
|||||||
bc->timeout_callback = timeout_callback;
|
bc->timeout_callback = timeout_callback;
|
||||||
bc->free_privdata = free_privdata;
|
bc->free_privdata = free_privdata;
|
||||||
bc->privdata = NULL;
|
bc->privdata = NULL;
|
||||||
c->bpop.timeout = timeout_ms;
|
c->bpop.timeout = timeout_ms ? (mstime()+timeout_ms) : 0;
|
||||||
|
|
||||||
blockClient(c,BLOCKED_MODULE);
|
blockClient(c,BLOCKED_MODULE);
|
||||||
return bc;
|
return bc;
|
||||||
@ -3157,7 +3157,11 @@ void moduleHandleBlockedClients(void) {
|
|||||||
ln = listFirst(moduleUnblockedClients);
|
ln = listFirst(moduleUnblockedClients);
|
||||||
bc = ln->value;
|
bc = ln->value;
|
||||||
client *c = bc->client;
|
client *c = bc->client;
|
||||||
listDelNode(server.unblocked_clients,ln);
|
listDelNode(moduleUnblockedClients,ln);
|
||||||
|
pthread_mutex_unlock(&moduleUnblockedClientsMutex);
|
||||||
|
|
||||||
|
/* Release the lock during the loop, as long as we don't
|
||||||
|
* touch the shared list. */
|
||||||
|
|
||||||
if (c != NULL) {
|
if (c != NULL) {
|
||||||
RedisModuleCtx ctx = REDISMODULE_CTX_INIT;
|
RedisModuleCtx ctx = REDISMODULE_CTX_INIT;
|
||||||
@ -3172,6 +3176,10 @@ void moduleHandleBlockedClients(void) {
|
|||||||
if (bc->privdata && bc->free_privdata)
|
if (bc->privdata && bc->free_privdata)
|
||||||
bc->free_privdata(bc->privdata);
|
bc->free_privdata(bc->privdata);
|
||||||
zfree(bc);
|
zfree(bc);
|
||||||
|
if (c != NULL) unblockClient(bc->client);
|
||||||
|
|
||||||
|
/* Lock again before to iterate the loop. */
|
||||||
|
pthread_mutex_lock(&moduleUnblockedClientsMutex);
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&moduleUnblockedClientsMutex);
|
pthread_mutex_unlock(&moduleUnblockedClientsMutex);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user