SORT with STORE removes key if result is empty. This fixes issue #227.

This commit is contained in:
Michal Kwiatkowski 2012-01-30 07:36:49 +01:00
parent 6c29410117
commit a0bf8d0ad8
3 changed files with 24 additions and 2 deletions

View File

@ -367,9 +367,14 @@ void sortCommand(redisClient *c) {
} }
} }
} }
if (outputlen) setKey(c->db,storekey,sobj); if (outputlen) {
setKey(c->db,storekey,sobj);
server.dirty += outputlen;
} else if (dbDelete(c->db,storekey)) {
signalModifiedKey(c->db,storekey);
server.dirty++;
}
decrRefCount(sobj); decrRefCount(sobj);
server.dirty += outputlen;
addReplyLongLong(c,outputlen); addReplyLongLong(c,outputlen);
} }

View File

@ -25,6 +25,16 @@ start_server {tags {"cas"}} {
r exec r exec
} {} } {}
test {EXEC fail on WATCHed key modified by SORT with STORE even if the result is empty} {
r flushdb
r lpush foo bar
r watch foo
r sort emptylist store foo
r multi
r ping
r exec
} {}
test {After successful EXEC key is no longer watched} { test {After successful EXEC key is no longer watched} {
r set x 30 r set x 30
r watch x r watch x

View File

@ -150,6 +150,13 @@ start_server {
r exists zap r exists zap
} {0} } {0}
test "SORT with STORE removes key if result is empty (github issue 227)" {
r flushdb
r lpush foo bar
r sort emptylist store foo
r exists foo
} {0}
tags {"slow"} { tags {"slow"} {
set num 100 set num 100
set res [create_random_dataset $num lpush] set res [create_random_dataset $num lpush]