mirror of
https://github.com/predis/predis.git
synced 2026-09-16 13:27:14 +00:00
Added more testing and cluster support
This commit is contained in:
@@ -183,6 +183,9 @@ abstract class ClusterStrategy implements StrategyInterface
|
||||
'XDEL' => $getKeyFromFirstArgument,
|
||||
'XRANGE' => $getKeyFromFirstArgument,
|
||||
|
||||
/* commands operating on time series */
|
||||
'TS.READ' => $getKeyFromFirstArgument,
|
||||
|
||||
/* commands operating on HyperLogLog */
|
||||
'PFADD' => $getKeyFromFirstArgument,
|
||||
'PFCOUNT' => $getKeyFromAllArguments,
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
namespace Predis\Command\Redis\TimeSeries;
|
||||
|
||||
use Predis\Command\Argument\ArrayableArgument;
|
||||
use Predis\Command\PrefixableCommand as RedisCommand;
|
||||
|
||||
/**
|
||||
@@ -30,11 +31,12 @@ class TSREAD extends RedisCommand
|
||||
|
||||
public function setArguments(array $arguments)
|
||||
{
|
||||
[$key, $timestamp] = $arguments;
|
||||
$commandArguments = (!empty($arguments[2])) ? $arguments[2]->toArray() : [];
|
||||
$commandArguments = ($arguments[2] ?? null) instanceof ArrayableArgument
|
||||
? $arguments[2]->toArray()
|
||||
: [];
|
||||
|
||||
parent::setArguments(array_merge(
|
||||
[$key, $timestamp],
|
||||
array_slice($arguments, 0, 2),
|
||||
$commandArguments
|
||||
));
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Predis\Command;
|
||||
|
||||
use Predis\ClientConfiguration;
|
||||
use Predis\Command\Redis\FUNCTIONS;
|
||||
use Predis\Command\Redis\TimeSeries\TSREAD;
|
||||
|
||||
/**
|
||||
* Command factory for mainline Redis servers.
|
||||
@@ -36,6 +37,8 @@ class RedisFactory extends Factory
|
||||
'OBJECT' => 'Predis\Command\Redis\OBJECT_',
|
||||
// Class name corresponds to PHP reserved word "function", added mapping to bypass restrictions
|
||||
'FUNCTION' => FUNCTIONS::class,
|
||||
// Wire ID mapping so cluster-routable module commands resolve by their command ID
|
||||
'TS.READ' => TSREAD::class,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -510,6 +510,9 @@ class PredisStrategyTest extends PredisTestCase
|
||||
'XDEL' => 'keys-first',
|
||||
'XRANGE' => 'keys-first',
|
||||
|
||||
/* commands operating on time series */
|
||||
'TS.READ' => 'keys-first',
|
||||
|
||||
/* commands operating on HyperLogLog */
|
||||
'PFADD' => 'keys-first',
|
||||
'PFCOUNT' => 'keys-all',
|
||||
|
||||
@@ -533,6 +533,9 @@ class RedisStrategyTest extends PredisTestCase
|
||||
'XDEL' => 'keys-first',
|
||||
'XRANGE' => 'keys-first',
|
||||
|
||||
/* commands operating on time series */
|
||||
'TS.READ' => 'keys-first',
|
||||
|
||||
/* commands operating on HyperLogLog */
|
||||
'PFADD' => 'keys-first',
|
||||
'PFCOUNT' => 'keys-all',
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (c) 2009-2020 Daniele Alessandri
|
||||
* (c) 2021-2026 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\Argument\TimeSeries;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ReadArgumentsTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ReadArguments
|
||||
*/
|
||||
private $arguments;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->arguments = new ReadArguments();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testReturnsEmptyArgumentsByDefault(): void
|
||||
{
|
||||
$this->assertSame([], $this->arguments->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testCreatesArgumentsWithBlockModifier(): void
|
||||
{
|
||||
$this->arguments->block(1000, 5);
|
||||
|
||||
$this->assertSame(['BLOCK', 1000, 5], $this->arguments->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testCreatesArgumentsWithZeroBlockTimeout(): void
|
||||
{
|
||||
$this->arguments->block(0, 1);
|
||||
|
||||
$this->assertSame(['BLOCK', 0, 1], $this->arguments->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testCreatesArgumentsWithMaxCountModifier(): void
|
||||
{
|
||||
$this->arguments->maxCount(10);
|
||||
|
||||
$this->assertSame(['MAX_COUNT', 10], $this->arguments->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testCreatesArgumentsWithAllModifiers(): void
|
||||
{
|
||||
$this->arguments
|
||||
->block(1000, 5)
|
||||
->maxCount(10);
|
||||
|
||||
$this->assertSame(['BLOCK', 1000, 5, 'MAX_COUNT', 10], $this->arguments->toArray());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user