8000 Add unit tests for -inf/inf/+inf WEIGHTS · jrtkcoder/phpredis@75ddd07 · GitHub
[go: up one dir, main page]

Skip to content

Commit 75ddd07

Browse files
Add unit tests for -inf/inf/+inf WEIGHTS
Addresses issue phpredis#336
1 parent e9d5e21 commit 75ddd07

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

tests/TestRedis.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1974,11 +1974,33 @@ public function testZX() {
19741974

19751975
$this->assertTrue($this->redis->zunion('key3', array('key1', 'key2'), array(2, 3.0)) === 3);
19761976

1977-
19781977
$this->redis->delete('key1');
19791978
$this->redis->delete('key2');
19801979
$this->redis->delete('key3');
19811980

1981+
// Test 'inf', '-inf', and '+inf' weights (GitHub issue #336)
1982+
$this->redis->zadd('key1', 1, 'one', 2, 'two', 3, 'three');
1983+
$this->redis->zadd('key2', 3, 'three', 4, 'four', 5, 'five');
1984+
1985+
// Make sure phpredis handles these weights
1986+
$this->assertTrue($this->redis->zunion('key3', array('key1','key2'), array(1, 'inf')) === 5);
1987+
$this->assertTrue($this->redis->zunion('key3', array('key1','key2'), array(1, '-inf')) === 5);
1988+
$this->assertTrue($this->redis->zunion('key3', array('key1','key2'), array(1, '+inf')) === 5);
1989+
1990+
// Now, confirm that they're being sent, and that it works
1991+
$arr_weights = Array('inf','-inf','+inf');
1992+
1993+
foreach($arr_weights as $str_weight) {
1994+
$r = $this->redis->zunionstore('key3', array('key1','key2'), array(1,$str_weight));
1995+
$this->assertTrue($r===5);
1996+
$r = $this->redis->zrangebyscore('key3', '(-inf', '(inf',array('withscores'=>true));
1997+
$this->assertTrue(count($r)===2);
1998+
$this->assertTrue(isset($r['one']));
1999+
$this->assertTrue(isset($r['two']));
2000+
}
2001+
2002+
$this->redis->del('key1','key2','key3');
2003+
19822004
$this->redis->zadd('key1', 2000.1, 'one');
19832005
$this->redis->zadd('key1', 3000.1, 'two');
19842006
$this->redis->zadd('key1', 4000.1, 'three');

0 commit comments

Comments
 (0)
0