mirror of
https://github.com/predis/predis.git
synced 2026-09-19 14:56:57 +00:00
662fdb99b3
* Added support for redis gears trigger function commands * Exclude gears tests from relay connection tests * Codestyle fixes * Added missing test coverage * Updated method description * Use redis-stack:edge image istead of separate container * Updated RESP3 modules responses * Removed redundant constants * Added additional timeout to make sure that index was created * Marked test as relay-incompatible * Mark tests as relay-incompatible * Mark tests as relay-incompatible * Increase timeout after index creation * Added support for trigger functions command run against OSS cluster * Mark gears cluster tests with appropriate annotation * Marked with cluster annotation * Codestyle fixes * Removed refresh cluster on connection, moved to refresh manually in tests * Removed redundant test * Updated README, added comments with README references * Revert "Marked test as relay-incompatible" This reverts commitd888968b7b. * Revert changes * Revert "Mark tests as relay-incompatible" This reverts commit7d34370c6b. * Revert "Updated RESP3 modules responses" This reverts commit5cf122ad71. * Removed latest image * Updated RESP3 modules responses (#4) * Marked tests as relay-incompatible (#3) * Marked test as relay-incompatible * Mark tests as relay-incompatible * Mark tests as relay-incompatible * Changed tests group for RESP3 not supported tests * Fixed broken tests * Removed redundant test * Marked test as relay-incompatible * Codestyle fixes * Updated CHANGELOG.md * Updated CHANGELOG.md * Revert php-cs-fixer style changes --------- Co-authored-by: Chayim <chayim@users.noreply.github.com>
215 lines
8.6 KiB
PHP
215 lines
8.6 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Predis package.
|
|
*
|
|
* (c) 2009-2020 Daniele Alessandri
|
|
* (c) 2021-2023 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\TimeSeries;
|
|
|
|
use Predis\Command\Argument\TimeSeries\CreateArguments;
|
|
use Predis\Command\Argument\TimeSeries\MRangeArguments;
|
|
use Predis\Command\Redis\PredisCommandTestCase;
|
|
|
|
/**
|
|
* @group commands
|
|
* @group realm-stack
|
|
*/
|
|
class TSMRANGE_Test extends PredisCommandTestCase
|
|
{
|
|
/**
|
|
* {@inheritDoc}
|
|
*/
|
|
protected function getExpectedCommand(): string
|
|
{
|
|
return TSMRANGE::class;
|
|
}
|
|
|
|
/**
|
|
* {@inheritDoc}
|
|
*/
|
|
protected function getExpectedId(): string
|
|
{
|
|
return 'TSMRANGE';
|
|
}
|
|
|
|
/**
|
|
* @group disconnected
|
|
* @dataProvider argumentsProvider
|
|
*/
|
|
public function testFilterArguments(array $actualArguments, array $expectedArguments): void
|
|
{
|
|
$command = $this->getCommand();
|
|
$command->setArguments($actualArguments);
|
|
|
|
$this->assertSameValues($expectedArguments, $command->getArguments());
|
|
}
|
|
|
|
/**
|
|
* @group disconnected
|
|
*/
|
|
public function testParseResponse(): void
|
|
{
|
|
$this->assertSame(1, $this->getCommand()->parseResponse(1));
|
|
}
|
|
|
|
/**
|
|
* @group connected
|
|
* @group relay-resp3
|
|
* @return void
|
|
* @requiresRedisTimeSeriesVersion >= 1.0.0
|
|
*/
|
|
public function testQueryRangeAcrossMultipleTimeSeriesInForwardDirection(): void
|
|
{
|
|
$redis = $this->getClient();
|
|
$expectedResponse = [
|
|
[
|
|
'type=stock',
|
|
[
|
|
['type', 'stock'],
|
|
['__reducer__', 'max'],
|
|
['__source__', 'stock:A,stock:B'],
|
|
],
|
|
[
|
|
[1000, '120'],
|
|
[1010, '110'],
|
|
[1020, '120'],
|
|
],
|
|
],
|
|
];
|
|
|
|
$this->assertEquals(
|
|
'OK',
|
|
$redis->tscreate('stock:A', (new CreateArguments())->labels('type', 'stock', 'name', 'A'))
|
|
);
|
|
$this->assertEquals(
|
|
'OK',
|
|
$redis->tscreate('stock:B', (new CreateArguments())->labels('type', 'stock', 'name', 'B'))
|
|
);
|
|
$this->assertSame(
|
|
[1000, 1010, 1020],
|
|
$redis->tsmadd('stock:A', 1000, 100, 'stock:A', 1010, 110, 'stock:A', 1020, 120)
|
|
);
|
|
$this->assertSame(
|
|
[1000, 1010, 1020],
|
|
$redis->tsmadd('stock:B', 1000, 120, 'stock:B', 1010, 110, 'stock:B', 1020, 100)
|
|
);
|
|
|
|
$mrangeArguments = (new MRangeArguments())
|
|
->withLabels()
|
|
->filter('type=stock')
|
|
->groupBy('type', 'max');
|
|
|
|
$this->assertEquals($expectedResponse, $redis->tsmrange('-', '+', $mrangeArguments));
|
|
}
|
|
|
|
/**
|
|
* @group connected
|
|
* @return void
|
|
* @requiresRedisTimeSeriesVersion >= 1.10.0
|
|
*/
|
|
public function testQueryRangeAcrossMultipleTimeSeriesInForwardDirectionResp3(): void
|
|
{
|
|
$redis = $this->getResp3Client();
|
|
$expectedResponse = [
|
|
'type=stock' => [
|
|
['type' => 'stock'],
|
|
['reducers' => ['max']],
|
|
['sources' => ['stock:A', 'stock:B']],
|
|
[
|
|
[1000, 120],
|
|
[1010, 110],
|
|
[1020, 120],
|
|
],
|
|
],
|
|
];
|
|
|
|
$this->assertEquals(
|
|
'OK',
|
|
$redis->tscreate('stock:A', (new CreateArguments())->labels('type', 'stock', 'name', 'A'))
|
|
);
|
|
$this->assertEquals(
|
|
'OK',
|
|
$redis->tscreate('stock:B', (new CreateArguments())->labels('type', 'stock', 'name', 'B'))
|
|
);
|
|
$this->assertSame(
|
|
[1000, 1010, 1020],
|
|
$redis->tsmadd('stock:A', 1000, 100, 'stock:A', 1010, 110, 'stock:A', 1020, 120)
|
|
);
|
|
$this->assertSame(
|
|
[1000, 1010, 1020],
|
|
$redis->tsmadd('stock:B', 1000, 120, 'stock:B', 1010, 110, 'stock:B', 1020, 100)
|
|
);
|
|
|
|
$mrangeArguments = (new MRangeArguments())
|
|
->withLabels()
|
|
->filter('type=stock')
|
|
->groupBy('type', 'max');
|
|
|
|
$this->assertEquals($expectedResponse, $redis->tsmrange('-', '+', $mrangeArguments));
|
|
}
|
|
|
|
public function argumentsProvider(): array
|
|
{
|
|
return [
|
|
'with default arguments' => [
|
|
[1000, 1001, (new MRangeArguments())->filter('filterExpression1', 'filterExpression2')],
|
|
[1000, 1001, 'FILTER', 'filterExpression1', 'filterExpression2'],
|
|
],
|
|
'with LATEST modifier' => [
|
|
[1000, 1001, (new MRangeArguments())->latest()->filter('filterExpression1', 'filterExpression2')],
|
|
[1000, 1001, 'LATEST', 'FILTER', 'filterExpression1', 'filterExpression2'],
|
|
],
|
|
'with FILTER_BY_TS modifier' => [
|
|
[1000, 1001, (new MRangeArguments())->filterByTs(1000, 1001)->filter('filterExpression1', 'filterExpression2')],
|
|
[1000, 1001, 'FILTER_BY_TS', 1000, 1001, 'FILTER', 'filterExpression1', 'filterExpression2'],
|
|
],
|
|
'with FILTER_BY_VALUE modifier' => [
|
|
[1000, 1001, (new MRangeArguments())->filterByValue(1000, 1001)->filter('filterExpression1', 'filterExpression2')],
|
|
[1000, 1001, 'FILTER_BY_VALUE', 1000, 1001, 'FILTER', 'filterExpression1', 'filterExpression2'],
|
|
],
|
|
'with WITHLABELS modifier' => [
|
|
[1000, 1001, (new MRangeArguments())->withLabels()->filter('filterExpression1', 'filterExpression2')],
|
|
[1000, 1001, 'WITHLABELS', 'FILTER', 'filterExpression1', 'filterExpression2'],
|
|
],
|
|
'with SELECTED_LABELS modifier' => [
|
|
[1000, 1001, (new MRangeArguments())->selectedLabels('label1', 'label2')->filter('filterExpression1', 'filterExpression2')],
|
|
[1000, 1001, 'SELECTED_LABELS', 'label1', 'label2', 'FILTER', 'filterExpression1', 'filterExpression2'],
|
|
],
|
|
'with COUNT modifier' => [
|
|
[1000, 1001, (new MRangeArguments())->count(2)->filter('filterExpression1', 'filterExpression2')],
|
|
[1000, 1001, 'COUNT', 2, 'FILTER', 'filterExpression1', 'filterExpression2'],
|
|
],
|
|
'with AGGREGATION modifier - default arguments' => [
|
|
[1000, 1001, (new MRangeArguments())->aggregation('sum', 2)->filter('filterExpression1', 'filterExpression2')],
|
|
[1000, 1001, 'AGGREGATION', 'sum', 2, 'FILTER', 'filterExpression1', 'filterExpression2'],
|
|
],
|
|
'with AGGREGATION modifier - with ALIGN' => [
|
|
[1000, 1001, (new MRangeArguments())->aggregation('sum', 2, 2)->filter('filterExpression1', 'filterExpression2')],
|
|
[1000, 1001, 'ALIGN', 2, 'AGGREGATION', 'sum', 2, 'FILTER', 'filterExpression1', 'filterExpression2'],
|
|
],
|
|
'with AGGREGATION modifier - with BUCKETTIMESTAMP' => [
|
|
[1000, 1001, (new MRangeArguments())->aggregation('sum', 2, 0, 10000)->filter('filterExpression1', 'filterExpression2')],
|
|
[1000, 1001, 'AGGREGATION', 'sum', 2, 'BUCKETTIMESTAMP', 10000, 'FILTER', 'filterExpression1', 'filterExpression2'],
|
|
],
|
|
'with AGGREGATION modifier - with EMPTY' => [
|
|
[1000, 1001, (new MRangeArguments())->aggregation('sum', 2, 0, 0, true)->filter('filterExpression1', 'filterExpression2')],
|
|
[1000, 1001, 'AGGREGATION', 'sum', 2, 'EMPTY', 'FILTER', 'filterExpression1', 'filterExpression2'],
|
|
],
|
|
'with GROUPBY modifier' => [
|
|
[1000, 1001, (new MRangeArguments())->filter('filterExpression1', 'filterExpression2')->groupBy('label', 'reducer')],
|
|
[1000, 1001, 'FILTER', 'filterExpression1', 'filterExpression2', 'GROUPBY', 'label', 'REDUCE', 'reducer'],
|
|
],
|
|
'with all modifiers' => [
|
|
[1000, 1001, (new MRangeArguments())->latest()->filterByTs(1000, 1001)->filterByValue(1000, 1001)->withLabels()->count(2)->aggregation('sum', 2)->filter('filterExpression1', 'filterExpression2')->groupBy('label', 'reducer'), 'filterExpression1', 'filterExpression2'],
|
|
[1000, 1001, 'LATEST', 'FILTER_BY_TS', 1000, 1001, 'FILTER_BY_VALUE', 1000, 1001, 'WITHLABELS', 'COUNT', 2, 'AGGREGATION', 'sum', 2, 'FILTER', 'filterExpression1', 'filterExpression2', 'GROUPBY', 'label', 'REDUCE', 'reducer'],
|
|
],
|
|
];
|
|
}
|
|
}
|