Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 93dae81

Browse files
author
Pepijn Verlaan
committed
Added failing test for brpoplpush command
1 parent 37a7c22 commit 93dae81

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

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)