diff --git a/library.c b/library.c index 6a93f49096..92e3de4cf1 100644 --- a/library.c +++ b/library.c @@ -203,8 +203,14 @@ PHPAPI char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_DC) resp = redis_sock_read_bulk_reply(redis_sock, *buf_len TSRMLS_CC); return resp; + case '*': + /* For null multi-bulk replies (like timeouts from brpoplpush): */ + if(memcmp(inbuf + 1, "-1", 2) == 0) { + return NULL; + } + /* fall through */ + case '+': - case '*': case ':': // Single Line Reply /* :123\r\n */ diff --git a/tests/TestRedis.php b/tests/TestRedis.php index 9f59d53525..1752b08151 100644 --- a/tests/TestRedis.php +++ b/tests/TestRedis.php @@ -1716,6 +1716,28 @@ public function testRpopLpush() { $this->assertTrue(array() === $this->redis->lgetRange('x', 0, -1)); $this->assertTrue(array() === $this->redis->lgetRange('y', 0, -1)); + } + + public function testBRpopLpush() { + + // standard case. + $this->redis->delete('x', 'y'); + $this->redis->lpush('x', 'abc'); + $this->redis->lpush('x', 'def'); // x = [def, abc] + + $this->redis->lpush('y', '123'); + $this->redis->lpush('y', '456'); // y = [456, 123] + + $this->assertEquals($this->redis->brpoplpush('x', 'y', 1), 'abc'); // we RPOP x, yielding abc. + $this->assertEquals($this->redis->lgetRange('x', 0, -1), array('def')); // only def remains in x. + $this->assertEquals($this->redis->lgetRange('y', 0, -1), array('abc', '456', '123')); // abc has been lpushed to y. + + // with an empty source, expecting no change. + $this->redis->delete('x', 'y'); + $this->assertTrue(FALSE === $this->redis->brpoplpush('x', 'y', 1)); + $this->assertTrue(array() === $this->redis->lgetRange('x', 0, -1)); + $this->assertTrue(array() === $this->redis->lgetRange('y', 0, -1)); + } public function testZAddFirstArg() {