From a0bf8d0ad8a6f4414194bc8ec7d067664bd321c2 Mon Sep 17 00:00:00 2001 From: Michal Kwiatkowski Date: Mon, 30 Jan 2012 07:36:49 +0100 Subject: [PATCH] SORT with STORE removes key if result is empty. This fixes issue #227. --- src/sort.c | 9 +++++++-- tests/unit/cas.tcl | 10 ++++++++++ tests/unit/sort.tcl | 7 +++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/sort.c b/src/sort.c index 7e50582e..038aec27 100644 --- a/src/sort.c +++ b/src/sort.c @@ -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); - server.dirty += outputlen; addReplyLongLong(c,outputlen); } diff --git a/tests/unit/cas.tcl b/tests/unit/cas.tcl index 082fba35..95766abe 100644 --- a/tests/unit/cas.tcl +++ b/tests/unit/cas.tcl @@ -25,6 +25,16 @@ start_server {tags {"cas"}} { 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} { r set x 30 r watch x diff --git a/tests/unit/sort.tcl b/tests/unit/sort.tcl index d8f93e83..38813065 100644 --- a/tests/unit/sort.tcl +++ b/tests/unit/sort.tcl @@ -150,6 +150,13 @@ start_server { r exists zap } {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"} { set num 100 set res [create_random_dataset $num lpush] -- 2.45.2