diff options
author | antirez <antirez@gmail.com> | 2017-07-14 13:02:15 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2017-07-14 13:02:53 +0200 |
commit | c29852ffd2e306fc33170c19777db7018b4938c4 (patch) | |
tree | 08d3a801d80e0d54a0f5eb2190df47f930a86fe2 | |
parent | b73f186aac96969d85baa3d8ee70dd2193a5a9c7 (diff) | |
download | redis-c29852ffd2e306fc33170c19777db7018b4938c4.tar.gz |
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.
-rw-r--r-- | src/module.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/module.c b/src/module.c index 7b8b17479..342612a1b 100644 --- a/src/module.c +++ b/src/module.c @@ -206,6 +206,7 @@ typedef struct RedisModuleBlockedClient { RedisModule_UnblockClient() API. */ client *reply_client; /* Fake client used to accumulate replies in thread safe contexts. */ + int dbid; /* Database number selected by the original client. */ } RedisModuleBlockedClient; static pthread_mutex_t moduleUnblockedClientsMutex = PTHREAD_MUTEX_INITIALIZER; @@ -3339,6 +3340,7 @@ RedisModuleBlockedClient *RM_BlockClient(RedisModuleCtx *ctx, RedisModuleCmdFunc bc->privdata = NULL; bc->reply_client = createClient(-1); bc->reply_client->flags |= CLIENT_MODULE; + bc->dbid = c->db->id; c->bpop.timeout = timeout_ms ? (mstime()+timeout_ms) : 0; blockClient(c,BLOCKED_MODULE); @@ -3524,6 +3526,7 @@ RedisModuleCtx *RM_GetThreadSafeContext(RedisModuleBlockedClient *bc) { * in order to keep things like the currently selected database and similar * things. */ ctx->client = createClient(-1); + if (bc) selectDb(ctx->client,bc->dbid); return ctx; } |