Skip to content

Commit

Permalink
[6.x] Fix the return type of spop for phpredis (#36106)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
zingimmick and taylorotwell committed Feb 1, 2021
1 parent 8182329 commit 3aa9657
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Redis/Connections/PhpRedisConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public function brpop(...$arguments)
*/
public function spop($key, $count = 1)
{
return $this->command('spop', [$key, $count]);
return $this->command('spop', func_get_args());
}

/**
Expand Down
27 changes: 27 additions & 0 deletions tests/Redis/RedisConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,33 @@ public function testItSscansForKeys()
}
}

public function testItSPopsForKeys()
{
foreach ($this->connections() as $redis) {
$members = ['test:spop:1', 'test:spop:2', 'test:spop:3', 'test:spop:4'];

foreach ($members as $member) {
$redis->sadd('set', $member);
}

$result = $redis->spop('set');
$this->assertIsNotArray($result);
$this->assertContains($result, $members);

$result = $redis->spop('set', 1);

$this->assertIsArray($result);
$this->assertCount(1, $result);

$result = $redis->spop('set', 2);

$this->assertIsArray($result);
$this->assertCount(2, $result);

$redis->flushAll();
}
}

public function testPhpRedisScanOption()
{
foreach ($this->connections() as $redis) {
Expand Down

0 comments on commit 3aa9657

Please sign in to comment.