Skip to content

Commit

Permalink
Merge pull request #87 from magnetik/zset-return
Browse files Browse the repository at this point in the history
Zset methods returns score as string
  • Loading branch information
omansour authored Aug 20, 2019
2 parents e10199c + 266e1ca commit 5f8821e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
9 changes: 3 additions & 6 deletions src/M6Web/Component/RedisMock/RedisMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ protected function zrangebyscoreHelper($key, $min, $max, array $options = array(
if ($min == '-inf' && $max == '+inf') {
$slice = array_slice(self::$dataValues[$this->storage][$key], $options['limit'][0], $options['limit'][1], true);
if (isset($options['withscores']) && $options['withscores']) {
return $this->returnPipedInfo($slice);
return $this->returnPipedInfo(array_map('strval', $slice));
} else {
return $this->returnPipedInfo(array_keys($slice));
}
Expand Down Expand Up @@ -947,14 +947,12 @@ protected function zrangebyscoreHelper($key, $min, $max, array $options = array(

$slice = array_slice($results, $options['limit'][0], $options['limit'][1], true);
if (isset($options['withscores']) && $options['withscores']) {
return $this->returnPipedInfo($slice);
return $this->returnPipedInfo(array_map('strval', $slice));
} else {
return $this->returnPipedInfo(array_keys($slice));
}
}



public function zrangebyscore($key, $min, $max, array $options = array())
{
return $this->zrangebyscoreHelper($key, $min, $max, $options, false);
Expand All @@ -965,7 +963,6 @@ public function zrevrangebyscore($key, $max, $min, array $options = array())
return $this->zrangebyscoreHelper($key, $min, $max, $options, true);
}


public function zadd($key, ...$args) {
if (count($args) === 1) {
if (count($args[0]) > 1) {
Expand Down Expand Up @@ -1010,7 +1007,7 @@ public function zscore($key, $member)
return $this->returnPipedInfo(null);
}

return $this->returnPipedInfo(self::$dataValues[$this->storage][$key][$member]);
return $this->returnPipedInfo((string) self::$dataValues[$this->storage][$key][$member]);
}

public function zcard($key)
Expand Down
30 changes: 15 additions & 15 deletions tests/units/RedisMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -717,11 +717,11 @@ public function testZScore()
$redisMock->zadd('test', 15, 'test2');

$this->assert
->integer($redisMock->zscore('test', 'test4'))
->string($redisMock->zscore('test', 'test4'))
->isEqualTo(1);

$this->assert
->integer($redisMock->zscore('test', 'test2'))
->string($redisMock->zscore('test', 'test2'))
->isEqualTo(15);

$this->assert
Expand Down Expand Up @@ -960,10 +960,10 @@ public function testZRevRange()
'test6',
))
->array($redisMock->zrevrange('test', 1, -3, true))
->isEqualTo(array(
'test2' => 15,
'test3' => 2,
'test4' => 1,
->isIdenticalTo(array(
'test2' => '15',
'test3' => '2',
'test4' => '1',
))
->integer($redisMock->del('test'))
->isEqualTo(6)
Expand Down Expand Up @@ -1058,10 +1058,10 @@ public function testZRangeByScore()
'test3',
))
->array($redisMock->zrangebyscore('test', '-inf', '15', array('limit' => array(1, 3), 'withscores' => true)))
->isEqualTo(array(
'test1' => 1,
'test4' => 1,
'test3' => 2,
->isIdenticalTo(array(
'test1' => '1',
'test4' => '1',
'test3' => '2',
))
->integer($redisMock->del('test'))
->isEqualTo(6)
Expand Down Expand Up @@ -1155,10 +1155,10 @@ public function testZRevRangeByScore()
'test1',
))
->array($redisMock->zrevrangebyscore('test', '15', '-inf', array('limit' => array(1, 3), 'withscores' => true)))
->isEqualTo(array(
'test3' => 2,
'test4' => 1,
'test1' => 1,
->isIdenticalTo(array(
'test3' => '2',
'test4' => '1',
'test1' => '1',
))
->integer($redisMock->del('test'))
->isEqualTo(6)
Expand All @@ -1171,7 +1171,7 @@ public function testZRevRangeByScore()
sleep(2);
$this->assert
->array($redisMock->zrevrangebyscore('test', '1', '0'))
->isEmpty();;
->isEmpty();
}

public function testHSetHMSetHGetHDelHExistsHKeysHLenHGetAll()
Expand Down

0 comments on commit 5f8821e

Please sign in to comment.