Skip to content

Commit 7aeacdd

Browse files
authored
Using an indexed array as the limit modifier for zrangebyscore. (#32952)
1 parent c65191a commit 7aeacdd

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/Illuminate/Redis/Connections/PhpRedisConnection.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Closure;
66
use Illuminate\Contracts\Redis\Connection as ConnectionContract;
7+
use Illuminate\Support\Arr;
78
use Illuminate\Support\Str;
89
use Redis;
910
use RedisCluster;
@@ -240,7 +241,7 @@ public function zadd($key, ...$dictionary)
240241
*/
241242
public function zrangebyscore($key, $min, $max, $options = [])
242243
{
243-
if (isset($options['limit'])) {
244+
if (isset($options['limit']) && Arr::isAssoc($options['limit'])) {
244245
$options['limit'] = [
245246
$options['limit']['offset'],
246247
$options['limit']['count'],
@@ -261,7 +262,7 @@ public function zrangebyscore($key, $min, $max, $options = [])
261262
*/
262263
public function zrevrangebyscore($key, $min, $max, $options = [])
263264
{
264-
if (isset($options['limit'])) {
265+
if (isset($options['limit']) && Arr::isAssoc($options['limit'])) {
265266
$options['limit'] = [
266267
$options['limit']['offset'],
267268
$options['limit']['count'],

tests/Redis/RedisConnectionTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,10 @@ public function testItReturnsRangeByScoreInSortedSet()
329329
'count' => 2,
330330
],
331331
]));
332+
$this->assertEquals(['matt' => 5, 'taylor' => 10], $redis->zrangebyscore('set', 0, 11, [
333+
'withscores' => true,
334+
'limit' => [1, 2],
335+
]));
332336

333337
$redis->flushall();
334338
}
@@ -346,6 +350,10 @@ public function testItReturnsRevRangeByScoreInSortedSet()
346350
'count' => 2,
347351
],
348352
]));
353+
$this->assertEquals(['matt' => 5, 'jeffrey' => 1], $redis->ZREVRANGEBYSCORE('set', 10, 0, [
354+
'withscores' => true,
355+
'limit' => [1, 2],
356+
]));
349357

350358
$redis->flushall();
351359
}

0 commit comments

Comments
 (0)