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

Skip to content

Commit 7c9420d

Browse files
Merge remote-tracking branch 'mheijkoop/zintersection_optional' into feature/zintersection_optional
2 parents a802461 + 68605de commit 7c9420d

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

redis.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4304,7 +4304,7 @@ PHPAPI void generic_z_command(INTERNAL_FUNCTION_PARAMETERS, char *command, int c
43044304
int cmd_len, cmd_elements;
43054305
int free_key_output;
43064306

4307-
if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osa|as",
4307+
if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osa|a!s",
43084308
&object, redis_ce,
43094309
&key_output, &key_output_len, &keys_array, &weights_array, &operation, &operation_len) == FAILURE) {
43104310
RETURN_FALSE;

tests/TestRedis.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1971,6 +1971,20 @@ public function testZX() {
19711971
$this->redis->delete('key2');
19721972
$this->redis->delete('key3');
19731973

1974+
//test zUnion with weights and aggegration function
1975+
$this->redis->zadd('key1', 1, 'duplicate');
1976+
$this->redis->zadd('key2', 2, 'duplicate');
1977+
$this->redis->zUnion('keyU', array('key1','key2'), array(1,1), 'MIN');
1978+
$this->assertTrue($this->redis->zScore('keyU', 'duplicate')===1.0);
1979+
$this->redis->delete('keyU');
1980+
1981+
//now test zUnion *without* weights but with aggregrate function
1982+
$this->redis->zUnion('keyU', array('key1','key2'), null, 'MIN');
1983+
$this->assertTrue($this->redis->zScore('keyU', 'duplicate')===1.0);
1984+
$this->redis->delete('keyU', 'key1', 'key2');
1985+
1986+
1987+
19741988
// test integer and float weights (GitHub issue #109).
19751989
$this->redis->del('key1', 'key2', 'key3');
19761990

@@ -2087,6 +2101,10 @@ public function testZX() {
20872101
$this->assertTrue( 2 === $this->redis->zInter('keyI', array('key1', 'key2', 'key3'), array(1, 5, 1), 'max'));
20882102
$this->assertTrue(array('val3', 'val1') === $this->redis->zRange('keyI', 0, -1));
20892103

2104+
$this->redis->delete('keyI');
2105+
$this->assertTrue(2 === $this->redis->zInter('keyI', array('key1', 'key2', 'key3'), null, 'max'));
2106+
$this->assertTrue($this->redis->zScore('keyI', 'val1') === floatval(7));
2107+
20902108
// zrank, zrevrank
20912109
$this->redis->delete('z');
20922110
$this->redis->zadd('z', 1, 'one');

0 commit comments

Comments
 (0)