From 4a5be21d6278ea7516848b73ada14eff56655ce4 Mon Sep 17 00:00:00 2001 From: predakanga <830645+predakanga@users.noreply.github.com> Date: Mon, 23 Feb 2026 19:31:19 +1100 Subject: [PATCH] Make LMPOP and BLMPOP commands prefixable (#1646) * Make LMPOP and BLMPOP commands prefixable * Update CHANGELOG --- CHANGELOG.md | 1 + src/Command/Redis/LMPOP.php | 23 ++++++++++++++++++- .../Processor/KeyPrefixProcessorTest.php | 8 +++++++ tests/Predis/Command/Redis/BLMPOP_Test.php | 19 +++++++++++++++ tests/Predis/Command/Redis/LMPOP_Test.php | 19 +++++++++++++++ 5 files changed, 69 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index baf70176..46538989 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Added - Make HTTL and HPTTL commands Prefixable (#1639) +- Make LMPOP and BLMPOP commands prefixable (#1643) ## v3.4.1 (2026-02-11) ### Fixed diff --git a/src/Command/Redis/LMPOP.php b/src/Command/Redis/LMPOP.php index 6a73321d..efcd76e7 100644 --- a/src/Command/Redis/LMPOP.php +++ b/src/Command/Redis/LMPOP.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\Count; use Predis\Command\Traits\Keys; use Predis\Command\Traits\LeftRight; @@ -63,4 +63,25 @@ class LMPOP extends RedisCommand { return $this->parseResponse($data); } + + public function prefixKeys($prefix) + { + $arguments = $this->getArguments(); + + $keysOffset = static::$keysArgumentPositionOffset; + $keysCount = $arguments[$keysOffset]; + $keys = array_slice($arguments, $keysOffset + 1, $keysCount); + $prefixedKeys = array_map(static function ($key) use ($prefix) { + return $prefix . $key; + }, $keys); + + $argumentsBefore = array_slice($arguments, 0, $keysOffset + 1); + $argumentsAfter = array_slice($arguments, $keysOffset + $keysCount + 1); + + $this->setRawArguments(array_merge( + $argumentsBefore, + $prefixedKeys, + $argumentsAfter + )); + } } diff --git a/tests/Predis/Command/Processor/KeyPrefixProcessorTest.php b/tests/Predis/Command/Processor/KeyPrefixProcessorTest.php index 714466ef..e2b63a30 100644 --- a/tests/Predis/Command/Processor/KeyPrefixProcessorTest.php +++ b/tests/Predis/Command/Processor/KeyPrefixProcessorTest.php @@ -858,6 +858,14 @@ class KeyPrefixProcessorTest extends PredisTestCase ['key'], ['prefix:key'], ], + ['LMPOP', + [['key1', 'key2', 'key3'], 'left', 10], + [3, 'prefix:key1', 'prefix:key2', 'prefix:key3', 'LEFT', 'COUNT', 10], + ], + ['BLMPOP', + [10, ['key1', 'key2', 'key3'], 'left', 10], + [10, 3, 'prefix:key1', 'prefix:key2', 'prefix:key3', 'LEFT', 'COUNT', 10], + ], /* ---------------- Redis 7.4 ---------------- */ ['HEXPIRE', ['key', 10, ['field1', 'field2']], diff --git a/tests/Predis/Command/Redis/BLMPOP_Test.php b/tests/Predis/Command/Redis/BLMPOP_Test.php index 064b7001..ee3f609f 100644 --- a/tests/Predis/Command/Redis/BLMPOP_Test.php +++ b/tests/Predis/Command/Redis/BLMPOP_Test.php @@ -12,6 +12,8 @@ namespace Predis\Command\Redis; +use Predis\Command\PrefixableCommand; + /** * @group commands * @group realm-list @@ -106,6 +108,23 @@ class BLMPOP_Test extends PredisCommandTestCase $this->assertSame(['elem2', 'elem1'], $redis->lrange('key', 0, -1)); } + /** + * @group disconnected + */ + public function testPrefixKeys(): void + { + /** @var PrefixableCommand $command */ + $command = $this->getCommand(); + $actualArguments = [10, ['key1', 'key2'], 'left', 10]; + $prefix = 'prefix:'; + $expectedArguments = [10, 2, 'prefix:key1', 'prefix:key2', 'LEFT', 'COUNT', 10]; + + $command->setArguments($actualArguments); + $command->prefixKeys($prefix); + + $this->assertSame($expectedArguments, $command->getArguments()); + } + public function argumentsProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/LMPOP_Test.php b/tests/Predis/Command/Redis/LMPOP_Test.php index 6e31c975..2355cb67 100644 --- a/tests/Predis/Command/Redis/LMPOP_Test.php +++ b/tests/Predis/Command/Redis/LMPOP_Test.php @@ -12,6 +12,8 @@ namespace Predis\Command\Redis; +use Predis\Command\PrefixableCommand; + /** * @group commands * @group realm-list @@ -104,6 +106,23 @@ class LMPOP_Test extends PredisCommandTestCase $this->assertSame(['elem2', 'elem1'], $redis->lrange('key', 0, -1)); } + /** + * @group disconnected + */ + public function testPrefixKeys(): void + { + /** @var PrefixableCommand $command */ + $command = $this->getCommand(); + $actualArguments = [['key1', 'key2'], 'left', 10]; + $prefix = 'prefix:'; + $expectedArguments = [2, 'prefix:key1', 'prefix:key2', 'LEFT', 'COUNT', 10]; + + $command->setArguments($actualArguments); + $command->prefixKeys($prefix); + + $this->assertSame($expectedArguments, $command->getArguments()); + } + public function argumentsProvider(): array { return [