mirror of
https://github.com/predis/predis.git
synced 2026-08-30 04:02:22 +00:00
Make LMPOP and BLMPOP commands prefixable (#1646)
* Make LMPOP and BLMPOP commands prefixable * Update CHANGELOG
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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']],
|
||||
|
||||
@@ -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 [
|
||||
|
||||
@@ -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 [
|
||||
|
||||
Reference in New Issue
Block a user