From 87264235cc59f9ad2b478e2d4d7c3104cceb9fdc Mon Sep 17 00:00:00 2001 From: Hamid Alaei Date: Thu, 4 Oct 2018 17:02:10 +0330 Subject: [PATCH] fix timer context selected database --- src/module.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/module.c b/src/module.c index 81b04f07..20d159d3 100644 --- a/src/module.c +++ b/src/module.c @@ -4221,6 +4221,7 @@ typedef struct RedisModuleTimer { RedisModule *module; /* Module reference. */ RedisModuleTimerProc callback; /* The callback to invoke on expire. */ void *data; /* Private data for the callback. */ + int dbid; /* Database number selected by the original client. */ } RedisModuleTimer; /* This is the timer handler that is called by the main event loop. We schedule @@ -4247,7 +4248,7 @@ int moduleTimerHandler(struct aeEventLoop *eventLoop, long long id, void *client ctx.module = timer->module; ctx.client = moduleFreeContextReusedClient; - selectDb(ctx.client, 0); + selectDb(ctx.client, timer->dbid); timer->callback(&ctx,timer->data); moduleFreeContext(&ctx); raxRemove(Timers,(unsigned char*)ri.key,ri.key_len,NULL); @@ -4272,6 +4273,7 @@ RedisModuleTimerID RM_CreateTimer(RedisModuleCtx *ctx, mstime_t period, RedisMod timer->module = ctx->module; timer->callback = callback; timer->data = data; + timer->dbid = ctx->client->db->id; uint64_t expiretime = ustime()+period*1000; uint64_t key;