diff --git a/src/multi.c b/src/multi.c index 1b708e859..1c1a17ee7 100644 --- a/src/multi.c +++ b/src/multi.c @@ -397,6 +397,10 @@ void touchWatchedKey(redisDb *db, robj *key) { client *c = listNodeValue(ln); c->flags |= CLIENT_DIRTY_CAS; + /* As the client is marked as dirty, there is no point in getting here + * again in case that key (or others) are modified again (or keep the + * memory overhead till EXEC). */ + unwatchAllKeys(c); } } @@ -426,6 +430,9 @@ void touchAllWatchedKeysInDb(redisDb *emptied, redisDb *replaced_with) { while((ln = listNext(&li))) { client *c = listNodeValue(ln); c->flags |= CLIENT_DIRTY_CAS; + /* As the client is marked as dirty, there is no point in getting here + * again for others keys (or keep the memory overhead till EXEC). */ + unwatchAllKeys(c); } } } @@ -439,6 +446,11 @@ void watchCommand(client *c) { addReplyError(c,"WATCH inside MULTI is not allowed"); return; } + /* No point in watching if the client is already dirty. */ + if (c->flags & CLIENT_DIRTY_CAS) { + addReply(c,shared.ok); + return; + } for (j = 1; j < c->argc; j++) watchForKey(c,c->argv[j]); addReply(c,shared.ok);