8000 Merge pull request #272 from pepve/brpoplpush · jrtkcoder/phpredis@07369ed · GitHub
[go: up one dir, main page]

Skip to content

Commit 07369ed

Browse files
author
Michael Grunder
committed
Merge pull request phpredis#272 from pepve/brpoplpush
Thanks for the pull, merging.
2 parents 93f77be + c7cb312 commit 07369ed

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

library.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,14 @@ PHPAPI char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_DC)
203203
resp = redis_sock_read_bulk_reply(redis_sock, *buf_len TSRMLS_CC);
204204
return resp;
205205

206+
case '*':
207+
/* For null multi-bulk replies (like timeouts from brpoplpush): */
208+
if(memcmp(inbuf + 1, "-1", 2) == 0) {
209+
return NULL;
210+
}
211+
/* fall through */
212+
206213
case '+':
207-
case '*':
208214
case ':':
209215
// Single Line Reply
210216
/* :123\r\n */

tests/TestRedis.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,6 +1716,28 @@ public function testRpopLpush() {
17161716
$this->assertTrue(array() === $this->redis->lgetRange('x', 0, -1));
17171717
$this->assertTrue(array() === $this->redis->lgetRange('y', 0, -1));
17181718

1719+
}
1720+
1721+
public function testBRpopLpush() {
1722+
1723+
// standard case.
1724+
$this->redis->delete('x', 'y');
1725+
$this->redis->lpush('x', 'abc');
1726+
$this->redis->lpush('x', 'def'); // x = [def, abc]
1727+
1728+
$this->redis->lpush('y', '123');
1729+
$this->redis->lpush('y', '456'); // y = [456, 123]
1730+
1731+
$this->assertEquals($this->redis->brpoplpush('x', 'y', 1), 'abc'); // we RPOP x, yielding abc.
1732+
$this->assertEquals($this->redis->lgetRange('x', 0, -1), array('def')); // only def remains in x.
1733+
$this->assertEquals($this->redis->lgetRange('y', 0, -1), array('abc', '456', '123')); // abc has been lpushed to y.
1734+
1735+
// with an empty source, expecting no change.
1736+
$this->redis->delete('x', 'y');
1737+
$this->assertTrue(FALSE === $this->redis->brpoplpush('x', 'y', 1));
1738+
$this->assertTrue(array() === $this->redis->lgetRange('x', 0, -1));
1739+
$this->assertTrue(array() === $this->redis->lgetRange('y', 0, -1));
1740+
17191741
}
17201742

17211743
public function testZAddFirstArg() {

0 commit comments

Comments
 (0)
0