diff --git a/src/t_list.c b/src/t_list.c index 2a98103333b71d9014983b78e0b05ea6fe8cccd9..6b4a611e47e257ad4a8b09f90610f96533a995a8 100644 --- a/src/t_list.c +++ b/src/t_list.c @@ -823,6 +823,13 @@ void blockingPopGenericCommand(redisClient *c, int where) { } } } + /* If we are inside a MULTI/EXEC and the list is empty the only thing + * we can do is treating it as a timeout (even with timeout 0). */ + if (c->flags & REDIS_MULTI) { + addReply(c,shared.nullmultibulk); + return; + } + /* If the list is empty or the key does not exists we must block */ timeout = strtol(c->argv[c->argc-1]->ptr,NULL,10); if (timeout > 0) timeout += time(NULL); diff --git a/tests/unit/type/list.tcl b/tests/unit/type/list.tcl index d3ed90ecc0fc174534983fe60a66bd3260aded9c..ca0da764470f73957a2202f04bdfb0853497dc0b 100644 --- a/tests/unit/type/list.tcl +++ b/tests/unit/type/list.tcl @@ -172,6 +172,17 @@ start_server { } } + test {BLPOP inside a transaction} { + r del xlist + r lpush xlist foo + r lpush xlist bar + r multi + r blpop xlist 0 + r blpop xlist 0 + r blpop xlist 0 + r exec + } {{xlist bar} {xlist foo} {}} + test {LPUSHX, RPUSHX - generic} { r del xlist assert_equal 0 [r lpushx xlist a]