Commit c29852ff authored by antirez's avatar antirez
Browse files

Modules: fix thread safe context DB selection.

Before this fix the DB currenty selected by the client blocked was not
respected and operations were always performed on DB 0.
parent b73f186a
...@@ -206,6 +206,7 @@ typedef struct RedisModuleBlockedClient { ...@@ -206,6 +206,7 @@ typedef struct RedisModuleBlockedClient {
RedisModule_UnblockClient() API. */ RedisModule_UnblockClient() API. */
client *reply_client; /* Fake client used to accumulate replies client *reply_client; /* Fake client used to accumulate replies
in thread safe contexts. */ in thread safe contexts. */
int dbid; /* Database number selected by the original client. */
} RedisModuleBlockedClient; } RedisModuleBlockedClient;
static pthread_mutex_t moduleUnblockedClientsMutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t moduleUnblockedClientsMutex = PTHREAD_MUTEX_INITIALIZER;
...@@ -3339,6 +3340,7 @@ RedisModuleBlockedClient *RM_BlockClient(RedisModuleCtx *ctx, RedisModuleCmdFunc ...@@ -3339,6 +3340,7 @@ RedisModuleBlockedClient *RM_BlockClient(RedisModuleCtx *ctx, RedisModuleCmdFunc
bc->privdata = NULL; bc->privdata = NULL;
bc->reply_client = createClient(-1); bc->reply_client = createClient(-1);
bc->reply_client->flags |= CLIENT_MODULE; bc->reply_client->flags |= CLIENT_MODULE;
bc->dbid = c->db->id;
c->bpop.timeout = timeout_ms ? (mstime()+timeout_ms) : 0; c->bpop.timeout = timeout_ms ? (mstime()+timeout_ms) : 0;
blockClient(c,BLOCKED_MODULE); blockClient(c,BLOCKED_MODULE);
...@@ -3524,6 +3526,7 @@ RedisModuleCtx *RM_GetThreadSafeContext(RedisModuleBlockedClient *bc) { ...@@ -3524,6 +3526,7 @@ RedisModuleCtx *RM_GetThreadSafeContext(RedisModuleBlockedClient *bc) {
* in order to keep things like the currently selected database and similar * in order to keep things like the currently selected database and similar
* things. */ * things. */
ctx->client = createClient(-1); ctx->client = createClient(-1);
if (bc) selectDb(ctx->client,bc->dbid);
return ctx; return ctx;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment