From 1ad7a18ec202a48c316ba35983bc309373811bf5 Mon Sep 17 00:00:00 2001 From: zingimmick Date: Mon, 1 Feb 2021 18:01:46 +0800 Subject: [PATCH 1/4] PhpRedis return value of spop compatibility --- .../Redis/Connections/PhpRedisConnection.php | 8 ++++-- tests/Redis/RedisConnectionTest.php | 27 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Redis/Connections/PhpRedisConnection.php b/src/Illuminate/Redis/Connections/PhpRedisConnection.php index 0950ec97cdcb..9dce11d7870d 100644 --- a/src/Illuminate/Redis/Connections/PhpRedisConnection.php +++ b/src/Illuminate/Redis/Connections/PhpRedisConnection.php @@ -195,9 +195,13 @@ public function brpop(...$arguments) * @param int|null $count * @return mixed|false */ - public function spop($key, $count = 1) + public function spop($key, $count = null) { - return $this->command('spop', [$key, $count]); + $parameters = [$key]; + if ($count !== null) { + $parameters[] = $count; + } + return $this->command('sPop', $parameters); } /** diff --git a/tests/Redis/RedisConnectionTest.php b/tests/Redis/RedisConnectionTest.php index 5326a09dd608..e3a04e6db591 100644 --- a/tests/Redis/RedisConnectionTest.php +++ b/tests/Redis/RedisConnectionTest.php @@ -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) { From d8b3bd372c4658ebe092868a7139b22f1ac6d3f8 Mon Sep 17 00:00:00 2001 From: zingimmick Date: Mon, 1 Feb 2021 18:23:33 +0800 Subject: [PATCH 2/4] fix style --- src/Illuminate/Redis/Connections/PhpRedisConnection.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Illuminate/Redis/Connections/PhpRedisConnection.php b/src/Illuminate/Redis/Connections/PhpRedisConnection.php index 9dce11d7870d..8ad85f2b3bd8 100644 --- a/src/Illuminate/Redis/Connections/PhpRedisConnection.php +++ b/src/Illuminate/Redis/Connections/PhpRedisConnection.php @@ -201,6 +201,7 @@ public function spop($key, $count = null) if ($count !== null) { $parameters[] = $count; } + return $this->command('sPop', $parameters); } From d0a97359e23d734f443fe5ddeeb273aa69c3f53f Mon Sep 17 00:00:00 2001 From: Zing Date: Mon, 1 Feb 2021 19:15:54 +0800 Subject: [PATCH 3/4] use func_get_args() instead of [$key, $count] --- .../Redis/Connections/PhpRedisConnection.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Illuminate/Redis/Connections/PhpRedisConnection.php b/src/Illuminate/Redis/Connections/PhpRedisConnection.php index 8ad85f2b3bd8..0579012ccf07 100644 --- a/src/Illuminate/Redis/Connections/PhpRedisConnection.php +++ b/src/Illuminate/Redis/Connections/PhpRedisConnection.php @@ -195,14 +195,10 @@ public function brpop(...$arguments) * @param int|null $count * @return mixed|false */ - public function spop($key, $count = null) + public function spop($key, $count = 1) { - $parameters = [$key]; - if ($count !== null) { - $parameters[] = $count; - } - - return $this->command('sPop', $parameters); + // use func_get_args() instead of [$key, $count] to fix the return type when called without the count argument. + return $this->command('spop', func_get_args()); } /** From 59a894364d2d7cf65dfb10e2e9bc7f439c4055fa Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 1 Feb 2021 08:54:00 -0600 Subject: [PATCH 4/4] Update PhpRedisConnection.php --- src/Illuminate/Redis/Connections/PhpRedisConnection.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Illuminate/Redis/Connections/PhpRedisConnection.php b/src/Illuminate/Redis/Connections/PhpRedisConnection.php index 0579012ccf07..0c4015df9880 100644 --- a/src/Illuminate/Redis/Connections/PhpRedisConnection.php +++ b/src/Illuminate/Redis/Connections/PhpRedisConnection.php @@ -197,7 +197,6 @@ public function brpop(...$arguments) */ public function spop($key, $count = 1) { - // use func_get_args() instead of [$key, $count] to fix the return type when called without the count argument. return $this->command('spop', func_get_args()); }