diff --git a/src/Command/Processor/KeyPrefixProcessor.php b/src/Command/Processor/KeyPrefixProcessor.php index d04e14dd..978c8100 100644 --- a/src/Command/Processor/KeyPrefixProcessor.php +++ b/src/Command/Processor/KeyPrefixProcessor.php @@ -33,6 +33,7 @@ class KeyPrefixProcessor implements ProcessorInterface $this->prefix = $prefix; $prefixFirst = static::class . '::first'; + $prefixFirstTwo = static::class . '::firstTwo'; $prefixAll = static::class . '::all'; $prefixInterleaved = static::class . '::interleaved'; $prefixSkipFirst = static::class . '::skipFirst'; @@ -198,6 +199,8 @@ class KeyPrefixProcessor implements ProcessorInterface /* ---------------- Redis 6.2 ---------------- */ 'GETDEL' => $prefixFirst, 'ZMSCORE' => $prefixFirst, + 'LMOVE' => $prefixFirstTwo, + 'BLMOVE' => $prefixFirstTwo, 'GEOSEARCH' => $prefixFirst, /* ---------------- Redis 7.0 ---------------- */ @@ -396,6 +399,24 @@ class KeyPrefixProcessor implements ProcessorInterface } } + /** + * Applies the specified prefix only to the first two arguments. + * + * @param CommandInterface $command Command instance. + * @param string $prefix Prefix string. + */ + public static function firstTwo(CommandInterface $command, $prefix) + { + $arguments = $command->getArguments(); + $length = min(count($arguments), 2); + + for ($i = 0; $i < $length; $i++) { + $arguments[$i] = "$prefix{$arguments[$i]}"; + } + + $command->setRawArguments($arguments); + } + /** * Applies the specified prefix to all the arguments. * diff --git a/tests/Predis/Command/Processor/KeyPrefixProcessorTest.php b/tests/Predis/Command/Processor/KeyPrefixProcessorTest.php index 1cadb544..f7da5e39 100644 --- a/tests/Predis/Command/Processor/KeyPrefixProcessorTest.php +++ b/tests/Predis/Command/Processor/KeyPrefixProcessorTest.php @@ -120,6 +120,37 @@ class KeyPrefixProcessorTest extends PredisTestCase $this->assertEmpty($command->getArguments()); } + /** + * @group disconnected + */ + public function testPrefixFirstTwo(): void + { + $arguments = ['1st', '2nd', '3rd', '4th']; + $expected = ['prefix:1st', 'prefix:2nd', '3rd', '4th']; + + $command = $this->getMockForAbstractClass('Predis\Command\Command'); + $command->setRawArguments($arguments); + + KeyPrefixProcessor::firstTwo($command, 'prefix:'); + $this->assertSame($expected, $command->getArguments()); + + // One argument + $arguments = ['1st']; + $expected = ['prefix:1st']; + + $command = $this->getMockForAbstractClass('Predis\Command\Command'); + $command->setRawArguments($arguments); + + KeyPrefixProcessor::firstTwo($command, 'prefix:'); + $this->assertSame($expected, $command->getArguments()); + + // Empty arguments + $command = $this->getMockForAbstractClass('Predis\Command\Command'); + + KeyPrefixProcessor::firstTwo($command, 'prefix:'); + $this->assertEmpty($command->getArguments()); + } + /** * @group disconnected */ @@ -978,6 +1009,14 @@ class KeyPrefixProcessorTest extends PredisTestCase ['key'], ['prefix:key'], ], + ['LMOVE', + ['key:source', 'key:destination', 'left', 'right'], + ['prefix:key:source', 'prefix:key:destination', 'left', 'right'], + ], + ['BLMOVE', + ['key:source', 'key:destination', 'left', 'right', 10], + ['prefix:key:source', 'prefix:key:destination', 'left', 'right', 10], + ], /* ---------------- Redis 7.0 ---------------- */ ['EXPIRETIME', ['key'],