diff --git a/src/ClientContextInterface.php b/src/ClientContextInterface.php index 85e4edcd..a24704e0 100644 --- a/src/ClientContextInterface.php +++ b/src/ClientContextInterface.php @@ -111,6 +111,7 @@ use Predis\Command\CommandInterface; * @method $this zcount($key, $min, $max) * @method $this zincrby($key, $increment, $member) * @method $this zinterstore($destination, array|string $keys, array $options = null) + * @method $this zmscore(string $key, string ...$member) * @method $this zrange($key, $start, $stop, array $options = null) * @method $this zrangebyscore($key, $min, $max, array $options = null) * @method $this zrank($key, $member) diff --git a/src/ClientInterface.php b/src/ClientInterface.php index e4bc0d96..6e4ebdb4 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -127,6 +127,7 @@ use Predis\Response\Status; * @method string zcount(string $key, int|string $min, int|string $max) * @method string zincrby(string $key, int $increment, string $member) * @method int zinterstore(string $destination, array|string $keys, array $options = null) + * @method array zmscore(string $key, string ...$member) * @method array zpopmin(string $key, int $count = 1) * @method array zpopmax(string $key, int $count = 1) * @method array zrange(string $key, int|string $start, int|string $stop, array $options = null) diff --git a/src/Command/Redis/ZMSCORE.php b/src/Command/Redis/ZMSCORE.php new file mode 100644 index 00000000..49a1dea0 --- /dev/null +++ b/src/Command/Redis/ZMSCORE.php @@ -0,0 +1,26 @@ += 6.2.0 + */ +class ZMSCORE extends RedisCommand +{ + /** + * @inheritDoc + */ + public function getId() + { + return 'ZMSCORE'; + } +} diff --git a/tests/Predis/Command/Redis/ZMSCORE_Test.php b/tests/Predis/Command/Redis/ZMSCORE_Test.php new file mode 100644 index 00000000..738e2cf0 --- /dev/null +++ b/tests/Predis/Command/Redis/ZMSCORE_Test.php @@ -0,0 +1,95 @@ +getCommand(); + $command->setArguments($arguments); + + $this->assertSame($expected, $command->getArguments()); + } + + /** + * @group disconnected + */ + public function testParseResponse(): void + { + $this->assertSame(1, $this->getCommand()->parseResponse(1)); + } + + /** + * @group connected + * @dataProvider membersProvider + * @requiresRedisVersion >= 6.2.0 + */ + public function testReturnsScoresAssociatedWithMembers( + string $key, + array $membersDictionary, + array $expectedResponse + ): void { + $redis = $this->getClient(); + $notExpectedMember = 'not_expected'; + + /** @var string[] $members */ + $members = array_filter($membersDictionary, static function($item) { + return is_string($item); + }); + + $redis->zadd($key, ...$membersDictionary); + + $this->assertSame($expectedResponse, $redis->zmscore($key, ...$members)); + $this->assertNull($redis->zmscore($key, $notExpectedMember)[0]); + } + + /** + * @group connected + * @requiresRedisVersion >= 6.2.0 + */ + public function testThrowsExceptionOnWrongType(): void + { + $this->expectException(ServerException::class); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + + $redis = $this->getClient(); + + $redis->set('foo', 'bar'); + $redis->zmscore('foo', ''); + } + + public function membersProvider(): array + { + return [['test-zscore', [1, 'member1', 2, 'member2', 3, 'member3'], ['1', '2', '3']]]; + } +}