From b211afd755aa4a892e3ae778e3b085b975f8c90e Mon Sep 17 00:00:00 2001 From: Markus Reinhold Date: Tue, 23 Dec 2025 12:27:27 +0100 Subject: [PATCH] Make ZRANDMEMBER prefixable (#1621) * Make ZRANDMEMBER prefixable * Update CHANGELOG.md --------- Co-authored-by: Vladyslav Vildanov <117659936+vladvildanov@users.noreply.github.com> --- CHANGELOG.md | 1 + src/Command/Redis/ZRANDMEMBER.php | 7 ++++++- .../Processor/KeyPrefixProcessorTest.php | 4 ++++ .../Predis/Command/Redis/ZRANDMEMBER_test.php | 18 ++++++++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 080efd8f..b7d9ed5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Fixed - Fixed wrong `@param` annotation in `Parameters` (#1614) +- Make `ZRANDMEMBER` prefixable (#1621) ### Added - Added retry support (#1616) diff --git a/src/Command/Redis/ZRANDMEMBER.php b/src/Command/Redis/ZRANDMEMBER.php index b1d2ca71..f1bbcbfb 100644 --- a/src/Command/Redis/ZRANDMEMBER.php +++ b/src/Command/Redis/ZRANDMEMBER.php @@ -12,7 +12,7 @@ namespace Predis\Command\Redis; -use Predis\Command\Command as RedisCommand; +use Predis\Command\PrefixableCommand as RedisCommand; use Predis\Command\Traits\With\WithScores; /** @@ -33,4 +33,9 @@ class ZRANDMEMBER extends RedisCommand { return 'ZRANDMEMBER'; } + + public function prefixKeys($prefix) + { + $this->applyPrefixForFirstArgument($prefix); + } } diff --git a/tests/Predis/Command/Processor/KeyPrefixProcessorTest.php b/tests/Predis/Command/Processor/KeyPrefixProcessorTest.php index a3486f19..714466ef 100644 --- a/tests/Predis/Command/Processor/KeyPrefixProcessorTest.php +++ b/tests/Predis/Command/Processor/KeyPrefixProcessorTest.php @@ -457,6 +457,10 @@ class KeyPrefixProcessorTest extends PredisTestCase ['key', 1.0, 'member'], ['prefix:key', 1.0, 'member'], ], + ['ZRANDMEMBER', + ['key', 10], + ['prefix:key', 10], + ], ['ZREM', ['key', 'member1', 'member2', 'member3'], ['prefix:key', 'member1', 'member2', 'member3'], diff --git a/tests/Predis/Command/Redis/ZRANDMEMBER_test.php b/tests/Predis/Command/Redis/ZRANDMEMBER_test.php index 8a956347..0eb99798 100644 --- a/tests/Predis/Command/Redis/ZRANDMEMBER_test.php +++ b/tests/Predis/Command/Redis/ZRANDMEMBER_test.php @@ -12,6 +12,7 @@ namespace Predis\Command\Redis; +use Predis\Command\PrefixableCommand; use Predis\Response\ServerException; class ZRANDMEMBER_test extends PredisCommandTestCase @@ -93,6 +94,23 @@ class ZRANDMEMBER_test extends PredisCommandTestCase $this->assertNull($redis->zrandmember($notExpectedKey)); } + /** + * @group disconnected + */ + public function testPrefixKeys(): void + { + /** @var PrefixableCommand $command */ + $command = $this->getCommand(); + $actualArguments = ['key', 10]; + $prefix = 'prefix:'; + $expectedArguments = ['prefix:key', 10]; + + $command->setArguments($actualArguments); + $command->prefixKeys($prefix); + + $this->assertSame($expectedArguments, $command->getArguments()); + } + /** * @group connected * @requiresRedisVersion >= 6.2.0