From 78fd4cb998212c0fd4baa623f94f23d6affc9986 Mon Sep 17 00:00:00 2001 From: BrightQi Date: Tue, 28 Jun 2022 23:23:35 +0800 Subject: [PATCH] bugfix for srem type to accept array #779 (#780) * bugfix for srem type to accept array #779 * add test to test SREM accept members as array type #779 --- src/ClientInterface.php | 2 +- tests/Predis/Command/Redis/SREM_Test.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/ClientInterface.php b/src/ClientInterface.php index 78c7430a..38d0e868 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -111,7 +111,7 @@ use Predis\Response\Status; * @method int smove(string $source, string $destination, string $member) * @method string|array|null spop(string $key, int $count = null) * @method string|null srandmember(string $key, int $count = null) - * @method int srem(string $key, string $member) + * @method int srem(string $key, array|string $member) * @method array sscan(string $key, int $cursor, array $options = null) * @method string[] sunion(array|string $keys) * @method int sunionstore(string $destination, array|string $keys) diff --git a/tests/Predis/Command/Redis/SREM_Test.php b/tests/Predis/Command/Redis/SREM_Test.php index fc5cc118..df7d6ef0 100644 --- a/tests/Predis/Command/Redis/SREM_Test.php +++ b/tests/Predis/Command/Redis/SREM_Test.php @@ -101,6 +101,22 @@ class SREM_Test extends PredisCommandTestCase $this->assertSame(0, $redis->srem('digits', 1)); } + /** + * @group connected + * @requiresRedisVersion >= 2.4.0 + */ + public function testRemovesMembersInArrayTypeFromSetVariadic(): void + { + $redis = $this->getClient(); + + $redis->sadd('letters', 'a', 'b', 'c', 'd'); + + $this->assertSame(2, $redis->srem('letters', ['b', 'd', 'z'])); + $this->assertSameValues(array('a', 'c'), $redis->smembers('letters')); + + $this->assertSame(0, $redis->srem('digits', [1])); + } + /** * @group connected */