|
11 | 11 | */ |
12 | 12 | class RedisMock extends atoum |
13 | 13 | { |
| 14 | + |
14 | 15 | public function testSetGetDelExists() |
15 | 16 | { |
16 | 17 | $redisMock = new Redis(); |
@@ -2077,44 +2078,62 @@ public function testSscanCommand() |
2077 | 2078 | public function testZscanCommand() |
2078 | 2079 | { |
2079 | 2080 | $redisMock = new Redis(); |
2080 | | - $redisMock->zadd('myZset', 1, 'a1'); |
2081 | | - $redisMock->zadd('myZset', ['b1' => 2, 'b2' => 3, 'b3' => 4, 'b4' => 5, 'b5' => 6, 'b6' => 7]); |
2082 | | - $redisMock->zadd('myZset', ['c1' => 8, 'c2' => 9, 'c3' => 10]); |
2083 | | - $redisMock->zadd('a/b', 11, 'c/d'); |
| 2081 | + $redisMock->zadd('set1', 1, 'a:1'); |
| 2082 | + $redisMock->zadd('set1', 2, 'b:1'); |
| 2083 | + $redisMock->zadd('set1', 3, 'c:1'); |
| 2084 | + $redisMock->zadd('set1', 4, 'd:1'); |
| 2085 | + |
| 2086 | + // Could be removed: ensure we have some noise of multiple sets |
| 2087 | + $redisMock->zadd('set2', 1, 'x:1'); |
| 2088 | + $redisMock->zadd('set2', 2, 'y:1'); |
| 2089 | + $redisMock->zadd('set2', 3, 'z:1'); |
2084 | 2090 |
|
2085 | 2091 | // It must return no values, as the key is unknown. |
2086 | 2092 | $this->assert |
2087 | | - ->array($redisMock->zscan('unknown', 1, ['COUNT' => 2])) |
| 2093 | + ->array($redisMock->zscan('unknown', 0, ['COUNT' => 10])) |
2088 | 2094 | ->isEqualTo([0, []]); |
2089 | 2095 |
|
| 2096 | + |
| 2097 | + // It must return all the values with score greater than or equal to 1. |
2090 | 2098 | $this->assert |
2091 | | - ->array($redisMock->zscan('a/b', 0, ['MATCH' => 'c/*'])) |
2092 | | - ->isEqualTo([0, [0 => 'c/d']]); |
| 2099 | + ->array($redisMock->zscan('set1', 0, ['MATCH' => '*', 'COUNT' => 10])) |
| 2100 | + ->isEqualTo([0 => 0, 1 => ['a:1' => 1, 'b:1' => 2, 'c:1' => 3, 'd:1' => 4]]); |
2093 | 2101 |
|
2094 | | - // It must return two values, start cursor after the first value of the set. |
| 2102 | + // It must return only the matched value |
2095 | 2103 | $this->assert |
2096 | | - ->array($redisMock->zscan('myZset', 1, ['COUNT' => 2])) |
2097 | | - ->isEqualTo([3, [0 => 'b1', 1 => 'b2']]); |
| 2104 | + ->array($redisMock->zscan('set1', 0, ['MATCH' => 'c*', 'COUNT' => 10])) |
| 2105 | + ->isEqualTo([0 => 0, 1 => ['c:1' => 3]]); |
| 2106 | + |
| 2107 | + // It must return all of the values based on the match of *1 |
| 2108 | + $this->assert |
| 2109 | + ->array($redisMock->zscan('set1', 0, ['MATCH' => '*1', 'COUNT' => 10])) |
| 2110 | + ->isEqualTo([0 => 0, 1 => ['a:1' => 1, 'b:1' => 2, 'c:1' => 3, 'd:1' => 4]]); |
| 2111 | + |
| 2112 | + // It must return two values, starting cursor after the first value of the list. |
2098 | 2113 |
|
2099 | | - // It must return all the values with score greater than or equal to 8. |
2100 | | - // And the cursor is defined after the default count (10) => the match has not terminate all the set. |
2101 | 2114 | $this->assert |
2102 | | - ->array($redisMock->zscan('myZset', 0, ['MATCH' => '*', 'COUNT' => 10])) |
2103 | | - ->isEqualTo([10, [0 => 'a1', 1 => 'b1', 2 => 'b2', 3 => 'b3', 4 => 'b4', 5 => 'b5', 6 => 'b6', 7 => 'c1', 8 => 'c2', 9 => 'c3']]); |
| 2115 | + ->array($redisMock->zscan('set1', 1, ['COUNT' => 2])) |
| 2116 | + ->isEqualTo([3, ['b:1' => 2, 'c:1' => 3]]); |
2104 | 2117 |
|
2105 | | - // Execute the match at the end of this set, the match not return an element (no one element match with the regex), |
2106 | | - // And the set is terminate, return the cursor to the start (0) |
| 2118 | + // Ensure if our results are complete we return a zero cursor |
2107 | 2119 | $this->assert |
2108 | | - ->array($redisMock->zscan('myZset', 11, ['MATCH' => 'd*'])) |
2109 | | - ->isEqualTo([0, []]); |
| 2120 | + ->array($redisMock->zscan('set1', 3, ['COUNT' => 2])) |
| 2121 | + ->isEqualTo([0, ['d:1' => 4]]); |
2110 | 2122 |
|
2111 | | - $redisMock->expire('myZset', 1); |
| 2123 | + // It must return all the values with score greater than or equal to 3, |
| 2124 | + // starting cursor after the last value of the previous scan. |
| 2125 | + $this->assert |
| 2126 | + ->array($redisMock->zscan('set1', 4, ['MATCH' => '*', 'COUNT' => 10])) |
| 2127 | + ->isEqualTo([0 => 0, 1 => []]); |
| 2128 | + |
| 2129 | + $redisMock->expire('set1', 1); |
2112 | 2130 | sleep(2); |
2113 | 2131 |
|
2114 | 2132 | // It must return no values, as the key is expired. |
2115 | 2133 | $this->assert |
2116 | | - ->array($redisMock->zscan('myZset', 1, ['COUNT' => 2])) |
| 2134 | + ->array($redisMock->zscan('set1', 0, ['COUNT' => 2])) |
2117 | 2135 | ->isEqualTo([0, []]); |
| 2136 | + |
2118 | 2137 | } |
2119 | 2138 |
|
2120 | 2139 | public function testBitcountCommand() |
|
0 commit comments