Skip to content

Commit 3aa9657

Browse files
[6.x] Fix the return type of spop for phpredis (#36106)
* PhpRedis return value of spop compatibility * fix style * use func_get_args() instead of [$key, $count] * Update PhpRedisConnection.php Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 8182329 commit 3aa9657

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/Illuminate/Redis/Connections/PhpRedisConnection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public function brpop(...$arguments)
197197
*/
198198
public function spop($key, $count = 1)
199199
{
200-
return $this->command('spop', [$key, $count]);
200+
return $this->command('spop', func_get_args());
201201
}
202202

203203
/**

tests/Redis/RedisConnectionTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,33 @@ public function testItSscansForKeys()
690690
}
691691
}
692692

693+
public function testItSPopsForKeys()
694+
{
695+
foreach ($this->connections() as $redis) {
696+
$members = ['test:spop:1', 'test:spop:2', 'test:spop:3', 'test:spop:4'];
697+
698+
foreach ($members as $member) {
699+
$redis->sadd('set', $member);
700+
}
701+
702+
$result = $redis->spop('set');
703+
$this->assertIsNotArray($result);
704+
$this->assertContains($result, $members);
705+
706+
$result = $redis->spop('set', 1);
707+
708+
$this->assertIsArray($result);
709+
$this->assertCount(1, $result);
710+
711+
$result = $redis->spop('set', 2);
712+
713+
$this->assertIsArray($result);
714+
$this->assertCount(2, $result);
715+
716+
$redis->flushAll();
717+
}
718+
}
719+
693720
public function testPhpRedisScanOption()
694721
{
695722
foreach ($this->connections() as $redis) {

0 commit comments

Comments
 (0)