Skip to content

Commit b35fdf1

Browse files
oranagraantirez
authored andcommitted
Avoid rejecting WATCH / UNWATCH, like MULTI/EXEC/DISCARD
Much like MULTI/EXEC/DISCARD, the WATCH and UNWATCH are not actually operating on the database or server state, but instead operate on the client state. the client may send them all in one long pipeline and check all the responses only at the end, so failing them may lead to a mismatch between the client state on the server and the one on the client end, and execute the wrong commands (ones that were meant to be discarded) the watched keys are not actually stored in the client struct, but they are in fact part of the client state. for instance, they're not cleared or moved in SWAPDB or FLUSHDB.
1 parent 1d7bf20 commit b35fdf1

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/server.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,11 +776,11 @@ struct redisCommand redisCommandTable[] = {
776776
0,NULL,0,0,0,0,0,0},
777777

778778
{"watch",watchCommand,-2,
779-
"no-script fast @transaction",
779+
"no-script fast ok-loading ok-stale @transaction",
780780
0,NULL,1,-1,1,0,0,0},
781781

782782
{"unwatch",unwatchCommand,1,
783-
"no-script fast @transaction",
783+
"no-script fast ok-loading ok-stale @transaction",
784784
0,NULL,0,0,0,0,0,0},
785785

786786
{"cluster",clusterCommand,-2,
@@ -3627,6 +3627,8 @@ int processCommand(client *c) {
36273627
c->cmd->proc != multiCommand &&
36283628
c->cmd->proc != execCommand &&
36293629
c->cmd->proc != discardCommand &&
3630+
c->cmd->proc != watchCommand &&
3631+
c->cmd->proc != unwatchCommand &&
36303632
!(c->cmd->proc == shutdownCommand &&
36313633
c->argc == 2 &&
36323634
tolower(((char*)c->argv[1]->ptr)[0]) == 'n') &&

0 commit comments

Comments
 (0)