Skip to content

Commit 5f8821e

Browse files
authored
Merge pull request #87 from magnetik/zset-return
Zset methods returns score as string
2 parents e10199c + 266e1ca commit 5f8821e

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

src/M6Web/Component/RedisMock/RedisMock.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ protected function zrangebyscoreHelper($key, $min, $max, array $options = array(
910910
if ($min == '-inf' && $max == '+inf') {
911911
$slice = array_slice(self::$dataValues[$this->storage][$key], $options['limit'][0], $options['limit'][1], true);
912912
if (isset($options['withscores']) && $options['withscores']) {
913-
return $this->returnPipedInfo($slice);
913+
return $this->returnPipedInfo(array_map('strval', $slice));
914914
} else {
915915
return $this->returnPipedInfo(array_keys($slice));
916916
}
@@ -947,14 +947,12 @@ protected function zrangebyscoreHelper($key, $min, $max, array $options = array(
947947

948948
$slice = array_slice($results, $options['limit'][0], $options['limit'][1], true);
949949
if (isset($options['withscores']) && $options['withscores']) {
950-
return $this->returnPipedInfo($slice);
950+
return $this->returnPipedInfo(array_map('strval', $slice));
951951
} else {
952952
return $this->returnPipedInfo(array_keys($slice));
953953
}
954954
}
955955

956-
957-
958956
public function zrangebyscore($key, $min, $max, array $options = array())
959957
{
960958
return $this->zrangebyscoreHelper($key, $min, $max, $options, false);
@@ -965,7 +963,6 @@ public function zrevrangebyscore($key, $max, $min, array $options = array())
965963
return $this->zrangebyscoreHelper($key, $min, $max, $options, true);
966964
}
967965

968-
969966
public function zadd($key, ...$args) {
970967
if (count($args) === 1) {
971968
if (count($args[0]) > 1) {
@@ -1010,7 +1007,7 @@ public function zscore($key, $member)
10101007
return $this->returnPipedInfo(null);
10111008
}
10121009

1013-
return $this->returnPipedInfo(self::$dataValues[$this->storage][$key][$member]);
1010+
return $this->returnPipedInfo((string) self::$dataValues[$this->storage][$key][$member]);
10141011
}
10151012

10161013
public function zcard($key)

tests/units/RedisMock.php

+15-15
Original file line numberDiff line numberDiff line change
@@ -717,11 +717,11 @@ public function testZScore()
717717
$redisMock->zadd('test', 15, 'test2');
718718

719719
$this->assert
720-
->integer($redisMock->zscore('test', 'test4'))
720+
->string($redisMock->zscore('test', 'test4'))
721721
->isEqualTo(1);
722722

723723
$this->assert
724-
->integer($redisMock->zscore('test', 'test2'))
724+
->string($redisMock->zscore('test', 'test2'))
725725
->isEqualTo(15);
726726

727727
$this->assert
@@ -960,10 +960,10 @@ public function testZRevRange()
960960
'test6',
961961
))
962962
->array($redisMock->zrevrange('test', 1, -3, true))
963-
->isEqualTo(array(
964-
'test2' => 15,
965-
'test3' => 2,
966-
'test4' => 1,
963+
->isIdenticalTo(array(
964+
'test2' => '15',
965+
'test3' => '2',
966+
'test4' => '1',
967967
))
968968
->integer($redisMock->del('test'))
969969
->isEqualTo(6)
@@ -1058,10 +1058,10 @@ public function testZRangeByScore()
10581058
'test3',
10591059
))
10601060
->array($redisMock->zrangebyscore('test', '-inf', '15', array('limit' => array(1, 3), 'withscores' => true)))
1061-
->isEqualTo(array(
1062-
'test1' => 1,
1063-
'test4' => 1,
1064-
'test3' => 2,
1061+
->isIdenticalTo(array(
1062+
'test1' => '1',
1063+
'test4' => '1',
1064+
'test3' => '2',
10651065
))
10661066
->integer($redisMock->del('test'))
10671067
->isEqualTo(6)
@@ -1155,10 +1155,10 @@ public function testZRevRangeByScore()
11551155
'test1',
11561156
))
11571157
->array($redisMock->zrevrangebyscore('test', '15', '-inf', array('limit' => array(1, 3), 'withscores' => true)))
1158-
->isEqualTo(array(
1159-
'test3' => 2,
1160-
'test4' => 1,
1161-
'test1' => 1,
1158+
->isIdenticalTo(array(
1159+
'test3' => '2',
1160+
'test4' => '1',
1161+
'test1' => '1',
11621162
))
11631163
->integer($redisMock->del('test'))
11641164
->isEqualTo(6)
@@ -1171,7 +1171,7 @@ public function testZRevRangeByScore()
11711171
sleep(2);
11721172
$this->assert
11731173
->array($redisMock->zrevrangebyscore('test', '1', '0'))
1174-
->isEmpty();;
1174+
->isEmpty();
11751175
}
11761176

11771177
public function testHSetHMSetHGetHDelHExistsHKeysHLenHGetAll()

0 commit comments

Comments
 (0)