Skip to content

Commit

Permalink
SMOVE only notify dstset when the addition is successful. (redis#9244)
Browse files Browse the repository at this point in the history
in case dest key already contains the member, the dest key isn't modified, so the command shouldn't invalidate watch.
  • Loading branch information
enjoy-binbin committed Jul 17, 2021
1 parent f03af47 commit 11dc4e5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/t_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,12 +392,12 @@ void smoveCommand(client *c) {
}

signalModifiedKey(c,c->db,c->argv[1]);
signalModifiedKey(c,c->db,c->argv[2]);
server.dirty++;

/* An extra key has changed when ele was successfully added to dstset */
if (setTypeAdd(dstset,ele->ptr)) {
server.dirty++;
signalModifiedKey(c,c->db,c->argv[2]);
notifyKeyspaceEvent(NOTIFY_SET,"sadd",c->argv[2],c->db->id);
}
addReply(c,shared.cone);
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/type/set.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,28 @@ start_server {
lsort [r smembers set{t}]
} {a b c}

test "SMOVE only notify dstset when the addition is successful" {
r del srcset{t}
r del dstset{t}

r sadd srcset{t} a b
r sadd dstset{t} a

r watch dstset{t}

r multi
r sadd dstset{t} c

set r2 [redis_client]
$r2 smove srcset{t} dstset{t} a

# The dstset is actually unchanged, multi should success
r exec
set res [r scard dstset{t}]
assert_equal $res 2
$r2 close
}

tags {slow} {
test {intsets implementation stress testing} {
for {set j 0} {$j < 20} {incr j} {
Expand Down

0 comments on commit 11dc4e5

Please sign in to comment.