mirror of
https://github.com/predis/predis.git
synced 2026-08-20 08:42:43 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9e9deec4df | |||
| c1845d96cc | |||
| 8f18de1c12 | |||
| 6d37dc45b0 | |||
| 1c96f704fc | |||
| b10cf7c96a |
@@ -39,7 +39,7 @@ jobs:
|
||||
run: |
|
||||
# Mapping of original redis versions to client test containers
|
||||
declare -A redis_clients_version_mapping=(
|
||||
["8.2"]="8.2-RC1-pre"
|
||||
["8.2"]="8.2"
|
||||
["8.0"]="8.0.2"
|
||||
["7.4"]="7.4.2"
|
||||
["7.2"]="7.2.7"
|
||||
|
||||
+14
-2
@@ -1,9 +1,21 @@
|
||||
## Changelog
|
||||
|
||||
### Unreleased
|
||||
## Unreleased
|
||||
### Added
|
||||
### Changed
|
||||
### Fixed
|
||||
### Maintenance
|
||||
|
||||
## v3.2.0 (2025-08-05)
|
||||
### Added
|
||||
- Added support for `XDELEX` and `XACKDEL` (#1580)
|
||||
- Added missing VSIM argument (#1582)
|
||||
|
||||
### Changed
|
||||
- Extended `XTRIM` and `XADD` commands with new parameters (#1580)
|
||||
|
||||
### Maintenance
|
||||
- Updated Redis 8.2 test image (#1583)
|
||||
- Added test coverage for updated Vamana (#1584)
|
||||
|
||||
## v3.1.0 (2025-07-22)
|
||||
### Added
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ use Traversable;
|
||||
*/
|
||||
class Client implements ClientInterface, IteratorAggregate
|
||||
{
|
||||
public const VERSION = '3.1.0';
|
||||
public const VERSION = '3.2.0';
|
||||
|
||||
/** @var OptionsInterface */
|
||||
private $options;
|
||||
|
||||
@@ -285,10 +285,12 @@ use Predis\Command\Redis\VADD;
|
||||
* @method $this tsrange(string $key, $fromTimestamp, $toTimestamp, ?RangeArguments $arguments = null)
|
||||
* @method $this tsrevrange(string $key, $fromTimestamp, $toTimestamp, ?RangeArguments $arguments = null)
|
||||
* @method $this xack(string $key, string $group, string ...$id)
|
||||
* @method $this xackdel(string $key, string $group, string $mode, array $ids)
|
||||
* @method $this xadd(string $key, array $dictionary, string $id = '*', array $options = null)
|
||||
* @method $this xautoclaim(string $key, string $group, string $consumer, int $minIdleTime, string $start, ?int $count = null, bool $justId = false)
|
||||
* @method $this xclaim(string $key, string $group, string $consumer, int $minIdleTime, string|array $ids, ?int $idle = null, ?int $time = null, ?int $retryCount = null, bool $force = false, bool $justId = false, ?string $lastId = null)
|
||||
* @method $this xdel(string $key, string ...$id)
|
||||
* @method $this xdelex(string $key, string $mode, array $ids)
|
||||
* @method $this xlen(string $key)
|
||||
* @method $this xpending(string $key, string $group, ?int $minIdleTime = null, ?string $start = null, ?string $end = null, ?int $count = null, ?string $consumer = null)
|
||||
* @method $this xrevrange(string $key, string $end, string $start, ?int $count = null)
|
||||
@@ -349,7 +351,7 @@ use Predis\Command\Redis\VADD;
|
||||
* @method $this vrandmember(string $key, int $count = null)
|
||||
* @method $this vrem(string $key, string $elem)
|
||||
* @method $this vsetattr(string $key, string $elem, string|array $attributes)
|
||||
* @method $this vsim(string $key, string|array $vectorOrElem, bool $isElem = false, bool $withScores = false, int $count = null, int $ef = null, string $filter = null, int $filterEf = null, bool $truth = false, bool $noThread = false)
|
||||
* @method $this vsim(string $key, string|array $vectorOrElem, bool $isElem = false, bool $withScores = false, int $count = null, float $epsilon = null, int $ef = null, string $filter = null, int $filterEf = null, bool $truth = false, bool $noThread = false)
|
||||
* @method $this watch($key)
|
||||
* @method $this eval($script, $numkeys, $keyOrArg1 = null, $keyOrArgN = null)
|
||||
* @method $this eval_ro(string $script, array $keys, ...$argument)
|
||||
|
||||
@@ -296,10 +296,12 @@ use Predis\Response\Status;
|
||||
* @method array tsrange(string $key, $fromTimestamp, $toTimestamp, ?RangeArguments $arguments = null)
|
||||
* @method array tsrevrange(string $key, $fromTimestamp, $toTimestamp, ?RangeArguments $arguments = null)
|
||||
* @method int xack(string $key, string $group, string ...$id)
|
||||
* @method array xackdel(string $key, string $group, string $mode, array $ids)
|
||||
* @method string xadd(string $key, array $dictionary, string $id = '*', array $options = null)
|
||||
* @method array xautoclaim(string $key, string $group, string $consumer, int $minIdleTime, string $start, ?int $count = null, bool $justId = false)
|
||||
* @method array xclaim(string $key, string $group, string $consumer, int $minIdleTime, string|array $ids, ?int $idle = null, ?int $time = null, ?int $retryCount = null, bool $force = false, bool $justId = false, ?string $lastId = null)
|
||||
* @method int xdel(string $key, string ...$id)
|
||||
* @method array xdelex(string $key, string $mode, array $ids)
|
||||
* @method int xlen(string $key)
|
||||
* @method array xpending(string $key, string $group, ?int $minIdleTime = null, ?string $start = null, ?string $end = null, ?int $count = null, ?string $consumer = null)
|
||||
* @method array xrevrange(string $key, string $end, string $start, ?int $count = null)
|
||||
@@ -360,7 +362,7 @@ use Predis\Response\Status;
|
||||
* @method array|null vlinks(string $key, string $elem, bool $withScores = false)
|
||||
* @method string|array|null vrandmember(string $key, int $count = null)
|
||||
* @method bool vrem(string $key, string $elem)
|
||||
* @method array vsim(string $key, string|array $vectorOrElem, bool $isElem = false, bool $withScores = false, int $count = null, int $ef = null, string $filter = null, int $filterEf = null, bool $truth = false, bool $noThread = false)
|
||||
* @method array vsim(string $key, string|array $vectorOrElem, bool $isElem = false, bool $withScores = false, int $count = null, float $epsilon = null, int $ef = null, string $filter = null, int $filterEf = null, bool $truth = false, bool $noThread = false)
|
||||
* @method bool vsetattr(string $key, string $elem, string|array $attributes)
|
||||
* @method array waitaof(int $numLocal, int $numReplicas, int $timeout)
|
||||
* @method mixed watch(string[]|string $keyOrKeys)
|
||||
|
||||
@@ -51,22 +51,26 @@ class VSIM extends RedisCommand
|
||||
}
|
||||
|
||||
if (isset($arguments[5])) {
|
||||
array_push($processedArguments, 'EF', $arguments[5]);
|
||||
array_push($processedArguments, 'EPSILON', $arguments[5]);
|
||||
}
|
||||
|
||||
if (isset($arguments[6])) {
|
||||
array_push($processedArguments, 'FILTER', $arguments[6]);
|
||||
array_push($processedArguments, 'EF', $arguments[6]);
|
||||
}
|
||||
|
||||
if (isset($arguments[7])) {
|
||||
array_push($processedArguments, 'FILTER-EF', $arguments[7]);
|
||||
array_push($processedArguments, 'FILTER', $arguments[7]);
|
||||
}
|
||||
|
||||
if (isset($arguments[8]) && false !== $arguments[8]) {
|
||||
$processedArguments[] = 'TRUTH';
|
||||
if (isset($arguments[8])) {
|
||||
array_push($processedArguments, 'FILTER-EF', $arguments[8]);
|
||||
}
|
||||
|
||||
if (isset($arguments[9]) && false !== $arguments[9]) {
|
||||
$processedArguments[] = 'TRUTH';
|
||||
}
|
||||
|
||||
if (isset($arguments[10]) && false !== $arguments[10]) {
|
||||
$processedArguments[] = 'NOTHREAD';
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (c) 2009-2020 Daniele Alessandri
|
||||
* (c) 2021-2025 Till Krüss
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis;
|
||||
|
||||
use Predis\Command\PrefixableCommand as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see http://redis.io/commands/xackdel
|
||||
*/
|
||||
class XACKDEL extends RedisCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return 'XACKDEL';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setArguments(array $arguments)
|
||||
{
|
||||
$processedArguments = [$arguments[0], $arguments[1], strtoupper($arguments[2])];
|
||||
|
||||
array_push($processedArguments, 'IDS', strval(count($arguments[3])), ...$arguments[3]);
|
||||
|
||||
parent::setArguments($processedArguments);
|
||||
}
|
||||
|
||||
public function prefixKeys($prefix)
|
||||
{
|
||||
$this->applyPrefixForFirstArgument($prefix);
|
||||
}
|
||||
}
|
||||
@@ -50,8 +50,13 @@ class XADD extends RedisCommand
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($options['trimming'])) {
|
||||
$args[] = strtoupper($options['trimming']);
|
||||
}
|
||||
|
||||
// ID, default to * to let Redis set it
|
||||
$args[] = $arguments[2] ?? '*';
|
||||
|
||||
if (isset($arguments[1]) && is_array($arguments[1])) {
|
||||
foreach ($arguments[1] as $key => $val) {
|
||||
$args[] = $key;
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (c) 2009-2020 Daniele Alessandri
|
||||
* (c) 2021-2025 Till Krüss
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis;
|
||||
|
||||
use Predis\Command\PrefixableCommand as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see http://redis.io/commands/xdelex
|
||||
*/
|
||||
class XDELEX extends RedisCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return 'XDELEX';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setArguments(array $arguments)
|
||||
{
|
||||
$processedArguments = [$arguments[0], strtoupper($arguments[1])];
|
||||
|
||||
array_push($processedArguments, 'IDS', strval(count($arguments[2])), ...$arguments[2]);
|
||||
|
||||
parent::setArguments($processedArguments);
|
||||
}
|
||||
|
||||
public function prefixKeys($prefix)
|
||||
{
|
||||
$this->applyPrefixForFirstArgument($prefix);
|
||||
}
|
||||
}
|
||||
@@ -49,6 +49,10 @@ class XTRIM extends RedisCommand
|
||||
$args[] = $options['limit'];
|
||||
}
|
||||
|
||||
if (isset($options['trimming'])) {
|
||||
$args[] = strtoupper($options['trimming']);
|
||||
}
|
||||
|
||||
parent::setArguments($args);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,10 @@ use Predis\Command\Argument\Search\SchemaFields\NumericField;
|
||||
use Predis\Command\Argument\Search\SchemaFields\TagField;
|
||||
use Predis\Command\Argument\Search\SchemaFields\TextField;
|
||||
use Predis\Command\Argument\Search\SchemaFields\VectorField;
|
||||
use Predis\Command\Argument\Search\SearchArguments;
|
||||
use Predis\Command\PrefixableCommand;
|
||||
use Predis\Command\Redis\PredisCommandTestCase;
|
||||
use Predis\Command\Redis\Utils\VectorUtility;
|
||||
|
||||
/**
|
||||
* @group commands
|
||||
@@ -194,6 +196,109 @@ class FTCREATE_Test extends PredisCommandTestCase
|
||||
$this->assertEquals('OK', $actualResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @group relay-resp3
|
||||
* @requiresRedisVersion >= 8.1.0
|
||||
* @return void
|
||||
*/
|
||||
public function testVectorCreateVANAMA(): void
|
||||
{
|
||||
$redis = $this->getClient();
|
||||
|
||||
$this->assertEquals('OK', $redis->ftcreate('test', [
|
||||
new VectorField(
|
||||
'v', 'SVS-VAMANA',
|
||||
['TYPE', 'FLOAT32',
|
||||
'DIM', 8,
|
||||
'DISTANCE_METRIC', 'L2',
|
||||
'COMPRESSION', 'LeanVec8x8', // LeanVec compression required for REDUCE
|
||||
'CONSTRUCTION_WINDOW_SIZE', 200,
|
||||
'GRAPH_MAX_DEGREE', 32,
|
||||
'SEARCH_WINDOW_SIZE', 15,
|
||||
'EPSILON', 0.01,
|
||||
'TRAINING_THRESHOLD', 1024,
|
||||
'REDUCE', 4,
|
||||
]// Half of DIM (8/2 = 4)
|
||||
),
|
||||
]));
|
||||
|
||||
$this->sleep(0.1);
|
||||
|
||||
// Create test vectors (8-dimensional to match DIM)
|
||||
$vectors = [
|
||||
[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0],
|
||||
[2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0],
|
||||
[3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0],
|
||||
[4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0],
|
||||
[5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0],
|
||||
];
|
||||
|
||||
foreach ($vectors as $i => $vector) {
|
||||
$redis->hset("doc{$i}", 'v', VectorUtility::toBlob($vector));
|
||||
}
|
||||
|
||||
$query = new SearchArguments();
|
||||
$query->params(['vec', VectorUtility::toBlob($vectors[0])]);
|
||||
$query->noContent();
|
||||
|
||||
$result = $redis->ftsearch('test', '*=>[KNN 3 @v $vec as score]', $query);
|
||||
|
||||
$this->assertSame(3, $result[0]);
|
||||
$this->assertSame('doc0', $result[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @requiresRedisVersion >= 8.1.0
|
||||
* @return void
|
||||
*/
|
||||
public function testVectorCreateVANAMAResp3(): void
|
||||
{
|
||||
$redis = $this->getResp3Client();
|
||||
|
||||
$this->assertEquals('OK', $redis->ftcreate('test', [
|
||||
new VectorField(
|
||||
'v', 'SVS-VAMANA',
|
||||
['TYPE', 'FLOAT32',
|
||||
'DIM', 8,
|
||||
'DISTANCE_METRIC', 'L2',
|
||||
'COMPRESSION', 'LeanVec8x8', // LeanVec compression required for REDUCE
|
||||
'CONSTRUCTION_WINDOW_SIZE', 200,
|
||||
'GRAPH_MAX_DEGREE', 32,
|
||||
'SEARCH_WINDOW_SIZE', 15,
|
||||
'EPSILON', 0.01,
|
||||
'TRAINING_THRESHOLD', 1024,
|
||||
'REDUCE', 4,
|
||||
]// Half of DIM (8/2 = 4)
|
||||
),
|
||||
]));
|
||||
|
||||
$this->sleep(0.1);
|
||||
|
||||
// Create test vectors (8-dimensional to match DIM)
|
||||
$vectors = [
|
||||
[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0],
|
||||
[2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0],
|
||||
[3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0],
|
||||
[4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0],
|
||||
[5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0],
|
||||
];
|
||||
|
||||
foreach ($vectors as $i => $vector) {
|
||||
$redis->hset("doc{$i}", 'v', VectorUtility::toBlob($vector));
|
||||
}
|
||||
|
||||
$query = new SearchArguments();
|
||||
$query->params(['vec', VectorUtility::toBlob($vectors[0])]);
|
||||
$query->noContent();
|
||||
|
||||
$result = $redis->ftsearch('test', '*=>[KNN 3 @v $vec as score]', $query);
|
||||
|
||||
$this->assertSame(3, count($result['results']));
|
||||
$this->assertSame('doc0', $result['results'][0]['id']);
|
||||
}
|
||||
|
||||
public function argumentsProvider(): array
|
||||
{
|
||||
return [
|
||||
@@ -275,21 +380,4 @@ class FTCREATE_Test extends PredisCommandTestCase
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @requiresRedisVersion >= 8.2.0
|
||||
* @return void
|
||||
*/
|
||||
public function testVectorCreateVANAMA(): void
|
||||
{
|
||||
$redis = $this->getClient();
|
||||
|
||||
$this->assertEquals('OK', $redis->ftcreate('test', [
|
||||
new VectorField(
|
||||
'svs-vanama', 'SVS-VAMANA',
|
||||
['TYPE', 'FLOAT32', 'DIM', 4, 'DISTANCE_METRIC', 'L2']
|
||||
),
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,11 +123,11 @@ class VSIM_Test extends PredisCommandTestCase
|
||||
$this->assertTrue($redis->vsetattr('key', 'elem3', ['years' => 16]));
|
||||
$this->assertTrue($redis->vsetattr('key', 'elem1', ['years' => 19]));
|
||||
|
||||
// with Filter expression
|
||||
// with Filter expression and Epsilon
|
||||
$this->assertSame(
|
||||
['elem2', 'elem1'],
|
||||
$redis->vsim(
|
||||
'key', [0.9, 0.8, 0.7, 0.6], false, false, null, null,
|
||||
'key', [0.9, 0.8, 0.7, 0.6], false, false, null, 0.2, null,
|
||||
'.years >= 18'
|
||||
)
|
||||
);
|
||||
@@ -192,11 +192,11 @@ class VSIM_Test extends PredisCommandTestCase
|
||||
$this->assertTrue($redis->vsetattr('key', 'elem3', ['years' => 16]));
|
||||
$this->assertTrue($redis->vsetattr('key', 'elem1', ['years' => 19]));
|
||||
|
||||
// with Filter expression
|
||||
// with Filter expression and Epsilon
|
||||
$this->assertSame(
|
||||
['elem2', 'elem1'],
|
||||
$redis->vsim(
|
||||
'key', [0.9, 0.8, 0.7, 0.6], false, false, null, null,
|
||||
'key', [0.9, 0.8, 0.7, 0.6], false, false, null, 0.2, null,
|
||||
'.years >= 18'
|
||||
)
|
||||
);
|
||||
@@ -225,24 +225,28 @@ class VSIM_Test extends PredisCommandTestCase
|
||||
['key', 'elem1', true, false, 10],
|
||||
['key', 'ELE', 'elem1', 'COUNT', 10],
|
||||
],
|
||||
'with EPSILON' => [
|
||||
['key', 'elem1', true, false, null, 0.01],
|
||||
['key', 'ELE', 'elem1', 'EPSILON', 0.01],
|
||||
],
|
||||
'with EF' => [
|
||||
['key', 'elem1', true, false, null, 50],
|
||||
['key', 'elem1', true, false, null, null, 50],
|
||||
['key', 'ELE', 'elem1', 'EF', 50],
|
||||
],
|
||||
'with FILTER' => [
|
||||
['key', 'elem1', true, false, null, null, '.year >= 1980 and .rating > 7'],
|
||||
['key', 'elem1', true, false, null, null, null, '.year >= 1980 and .rating > 7'],
|
||||
['key', 'ELE', 'elem1', 'FILTER', '.year >= 1980 and .rating > 7'],
|
||||
],
|
||||
'with FILTER-EF' => [
|
||||
['key', 'elem1', true, false, null, null, null, 50],
|
||||
['key', 'elem1', true, false, null, null, null, null, 50],
|
||||
['key', 'ELE', 'elem1', 'FILTER-EF', 50],
|
||||
],
|
||||
'with TRUTH' => [
|
||||
['key', 'elem1', true, false, null, null, null, null, true],
|
||||
['key', 'elem1', true, false, null, null, null, null, null, true],
|
||||
['key', 'ELE', 'elem1', 'TRUTH'],
|
||||
],
|
||||
'with NOTHREAD' => [
|
||||
['key', 'elem1', true, false, null, null, null, null, false, true],
|
||||
['key', 'elem1', true, false, null, null, null, null, null, false, true],
|
||||
['key', 'ELE', 'elem1', 'NOTHREAD'],
|
||||
],
|
||||
];
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (c) 2009-2020 Daniele Alessandri
|
||||
* (c) 2021-2025 Till Krüss
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis;
|
||||
|
||||
use Predis\Command\PrefixableCommand;
|
||||
|
||||
/**
|
||||
* @group commands
|
||||
* @group realm-stream
|
||||
*/
|
||||
class XACKDEL_Test extends PredisCommandTestCase
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedCommand(): string
|
||||
{
|
||||
return 'Predis\Command\Redis\XACKDEL';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedId(): string
|
||||
{
|
||||
return 'XACKDEL';
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testFilterArgumentsWithKEEPREF(): void
|
||||
{
|
||||
$arguments = ['stream', 'group1', 'KEEPREF', ['id1', 'id2']];
|
||||
$expected = ['stream', 'group1', 'KEEPREF', 'IDS', '2', 'id1', 'id2'];
|
||||
|
||||
$command = $this->getCommand();
|
||||
$command->setArguments($arguments);
|
||||
|
||||
$this->assertSame($expected, $command->getArguments());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testFilterArgumentsWithDELREF(): void
|
||||
{
|
||||
$arguments = ['stream', 'group1', 'DELREF', ['id1', 'id2', 'id3']];
|
||||
$expected = ['stream', 'group1', 'DELREF', 'IDS', '3', 'id1', 'id2', 'id3'];
|
||||
|
||||
$command = $this->getCommand();
|
||||
$command->setArguments($arguments);
|
||||
|
||||
$this->assertSame($expected, $command->getArguments());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testFilterArgumentsWithACKED(): void
|
||||
{
|
||||
$arguments = ['stream', 'group1', 'ACKED', ['id1']];
|
||||
$expected = ['stream', 'group1', 'ACKED', 'IDS', '1', 'id1'];
|
||||
|
||||
$command = $this->getCommand();
|
||||
$command->setArguments($arguments);
|
||||
|
||||
$this->assertSame($expected, $command->getArguments());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testParseResponse(): void
|
||||
{
|
||||
$this->assertSame([1, 2, -1], $this->getCommand()->parseResponse([1, 2, -1]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testPrefixKeys(): void
|
||||
{
|
||||
/** @var PrefixableCommand $command */
|
||||
$command = $this->getCommand();
|
||||
$actualArguments = ['stream', 'group1', 'DELREF', ['id1', 'id2']];
|
||||
$prefix = 'prefix:';
|
||||
$expectedArguments = ['prefix:stream', 'group1', 'DELREF', 'IDS', '2', 'id1', 'id2'];
|
||||
|
||||
$command->setArguments($actualArguments);
|
||||
$command->prefixKeys($prefix);
|
||||
|
||||
$this->assertSame($expectedArguments, $command->getArguments());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @requiresRedisVersion >= 8.2.0
|
||||
*/
|
||||
public function testAcknowledgesAndDeletesSpecifiedMembers(): void
|
||||
{
|
||||
$redis = $this->getClient();
|
||||
|
||||
$redis->xadd('teststream', ['key0' => 'val0'], '0-1');
|
||||
$redis->xadd('teststream', ['key1' => 'val1'], '1-1');
|
||||
$redis->xadd('teststream', ['key2' => 'val2'], '2-1');
|
||||
|
||||
$redis->xgroup->create('teststream', 'testgroup', '0');
|
||||
|
||||
$redis->xreadgroup('testgroup', 'consumer1', 2, null, false, 'teststream', '>');
|
||||
|
||||
$result = $redis->xackdel('teststream', 'testgroup', 'KEEPREF', ['0-1', '1-1']);
|
||||
|
||||
$this->assertIsArray($result);
|
||||
$this->assertCount(2, $result);
|
||||
|
||||
$redis->xadd('teststream', ['key3' => 'val3'], '3-1');
|
||||
$redis->xreadgroup('testgroup', 'consumer1', 1, null, false, 'teststream', '>');
|
||||
$result2 = $redis->xackdel('teststream', 'testgroup', 'KEEPREF', ['3-1']);
|
||||
|
||||
$this->assertIsArray($result2);
|
||||
$this->assertCount(1, $result2);
|
||||
}
|
||||
}
|
||||
@@ -112,6 +112,26 @@ class XADD_Test extends PredisCommandTestCase
|
||||
['stream', '*', 'key', 'val'],
|
||||
];
|
||||
|
||||
$data[] = [
|
||||
['stream', ['key' => 'val'], '2-3', ['trimming' => 'KEEPREF']],
|
||||
['stream', 'KEEPREF', '2-3', 'key', 'val'],
|
||||
];
|
||||
|
||||
$data[] = [
|
||||
['stream', ['key' => 'val'], '*', ['trimming' => 'KEEPREF']],
|
||||
['stream', 'KEEPREF', '*', 'key', 'val'],
|
||||
];
|
||||
|
||||
$data[] = [
|
||||
[
|
||||
'stream',
|
||||
['key' => 'val'],
|
||||
'*',
|
||||
['trim' => ['MINID', '~', '0-1'], 'limit' => 5, 'nomkstream' => true, 'trimming' => 'KEEPREF'],
|
||||
],
|
||||
['stream', 'NOMKSTREAM', 'MINID', '~', '0-1', 'LIMIT', 5, 'KEEPREF', '*', 'key', 'val'],
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (c) 2009-2020 Daniele Alessandri
|
||||
* (c) 2021-2025 Till Krüss
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis;
|
||||
|
||||
use Predis\Command\PrefixableCommand;
|
||||
|
||||
/**
|
||||
* @group commands
|
||||
* @group realm-stream
|
||||
*/
|
||||
class XDELEX_Test extends PredisCommandTestCase
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedCommand(): string
|
||||
{
|
||||
return 'Predis\Command\Redis\XDELEX';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedId(): string
|
||||
{
|
||||
return 'XDELEX';
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testFilterArgumentsWithKEEPREF(): void
|
||||
{
|
||||
$arguments = ['stream', 'KEEPREF', ['id1', 'id2']];
|
||||
$expected = ['stream', 'KEEPREF', 'IDS', '2', 'id1', 'id2'];
|
||||
|
||||
$command = $this->getCommand();
|
||||
$command->setArguments($arguments);
|
||||
|
||||
$this->assertSame($expected, $command->getArguments());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testFilterArgumentsWithDELREF(): void
|
||||
{
|
||||
$arguments = ['stream', 'DELREF', ['id1', 'id2', 'id3']];
|
||||
$expected = ['stream', 'DELREF', 'IDS', '3', 'id1', 'id2', 'id3'];
|
||||
|
||||
$command = $this->getCommand();
|
||||
$command->setArguments($arguments);
|
||||
|
||||
$this->assertSame($expected, $command->getArguments());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testFilterArgumentsWithACKED(): void
|
||||
{
|
||||
$arguments = ['stream', 'ACKED', ['id1']];
|
||||
$expected = ['stream', 'ACKED', 'IDS', '1', 'id1'];
|
||||
|
||||
$command = $this->getCommand();
|
||||
$command->setArguments($arguments);
|
||||
|
||||
$this->assertSame($expected, $command->getArguments());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testParseResponse(): void
|
||||
{
|
||||
$this->assertSame([1, 2, -1], $this->getCommand()->parseResponse([1, 2, -1]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testPrefixKeys(): void
|
||||
{
|
||||
/** @var PrefixableCommand $command */
|
||||
$command = $this->getCommand();
|
||||
$actualArguments = ['stream', 'DELREF', ['id1', 'id2']];
|
||||
$prefix = 'prefix:';
|
||||
$expectedArguments = ['prefix:stream', 'DELREF', 'IDS', '2', 'id1', 'id2'];
|
||||
|
||||
$command->setArguments($actualArguments);
|
||||
$command->prefixKeys($prefix);
|
||||
|
||||
$this->assertSame($expectedArguments, $command->getArguments());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @requiresRedisVersion >= 8.2.0
|
||||
*/
|
||||
public function testRemovesSpecifiedMembersWithXdelex(): void
|
||||
{
|
||||
$redis = $this->getClient();
|
||||
|
||||
$redis->xadd('teststream', ['key0' => 'val0'], '0-1');
|
||||
$redis->xadd('teststream', ['key1' => 'val1'], '1-1');
|
||||
$redis->xadd('teststream', ['key2' => 'val2'], '2-1');
|
||||
|
||||
$result = $redis->xdelex('teststream', 'KEEPREF', ['0-1', '2-1']);
|
||||
|
||||
$this->assertIsArray($result);
|
||||
$this->assertCount(2, $result);
|
||||
|
||||
$remaining = $redis->xrange('teststream', '-', '+');
|
||||
$this->assertSame(['1-1' => ['key1' => 'val1']], $remaining);
|
||||
|
||||
$redis->xadd('teststream', ['key3' => 'val3'], '3-1');
|
||||
$result2 = $redis->xdelex('teststream', 'KEEPREF', ['3-1']);
|
||||
|
||||
$this->assertIsArray($result2);
|
||||
$this->assertCount(1, $result2);
|
||||
}
|
||||
}
|
||||
@@ -84,6 +84,18 @@ class XTRIM_Test extends PredisCommandTestCase
|
||||
['stream', 'MINID', '0-1'],
|
||||
['stream', 'MINID', '0-1'],
|
||||
],
|
||||
[
|
||||
['stream', 'MINID', '0-1', ['trimming' => 'KEEPREF']],
|
||||
['stream', 'MINID', '0-1', 'KEEPREF'],
|
||||
],
|
||||
[
|
||||
['stream', 'MINID', '0-1', ['limit' => 10, 'trimming' => 'KEEPREF']],
|
||||
['stream', 'MINID', '0-1', 'LIMIT', 10, 'KEEPREF'],
|
||||
],
|
||||
[
|
||||
['stream', ['MINID'], '0-1', ['limit' => 10, 'trimming' => 'ACKED']],
|
||||
['stream', 'MINID', '0-1', 'LIMIT', 10, 'ACKED'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user