summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSalvatore Sanfilippo <antirez@gmail.com>2017-11-23 13:38:43 +0100
committerGitHub <noreply@github.com>2017-11-23 13:38:43 +0100
commitada206559db76b2103c446c2691cb06fbc8c5d31 (patch)
tree93f486efc17c94a72d28fa23a2a975584582479c
parent57bd8feb8d81064cd53a7f124e7509134fb7459b (diff)
parent2c70d28295b38060692881c7824df602ade6c4cb (diff)
downloadredis-ada206559db76b2103c446c2691cb06fbc8c5d31.tar.gz
Merge pull request #4467 from yossigo/fix-nested-multi
Nested MULTI/EXEC may replicate in different cases.
-rw-r--r--src/module.c2
-rw-r--r--src/scripting.c8
2 files changed, 10 insertions, 0 deletions
diff --git a/src/module.c b/src/module.c
index afeb6e2cf..03857ee44 100644
--- a/src/module.c
+++ b/src/module.c
@@ -1164,6 +1164,8 @@ int RM_ReplyWithDouble(RedisModuleCtx *ctx, double d) {
* in the context of a command execution. EXEC will be handled by the
* RedisModuleCommandDispatcher() function. */
void moduleReplicateMultiIfNeeded(RedisModuleCtx *ctx) {
+ /* Skip this if client explicitly wrap the command with MULTI */
+ if (ctx->client->flags & CLIENT_MULTI) return;
/* If we already emitted MULTI return ASAP. */
if (ctx->flags & REDISMODULE_CTX_MULTI_EMITTED) return;
/* If this is a thread safe context, we do not want to wrap commands
diff --git a/src/scripting.c b/src/scripting.c
index 8f8145b2c..d9f954068 100644
--- a/src/scripting.c
+++ b/src/scripting.c
@@ -358,6 +358,13 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) {
static size_t cached_objects_len[LUA_CMD_OBJCACHE_SIZE];
static int inuse = 0; /* Recursive calls detection. */
+ /* Reflect MULTI state */
+ if (server.lua_multi_emitted || (server.lua_caller->flags & CLIENT_MULTI)) {
+ c->flags |= CLIENT_MULTI;
+ } else {
+ c->flags &= ~CLIENT_MULTI;
+ }
+
/* By using Lua debug hooks it is possible to trigger a recursive call
* to luaRedisGenericCommand(), which normally should never happen.
* To make this function reentrant is futile and makes it slower, but
@@ -535,6 +542,7 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) {
* a Lua script in the context of AOF and slaves. */
if (server.lua_replicate_commands &&
!server.lua_multi_emitted &&
+ !(server.lua_caller->flags & CLIENT_MULTI) &&
server.lua_write_dirty &&
server.lua_repl != PROPAGATE_NONE)
{