Extended TimeSeries support by implementing TS.DELETERULE command (#1227)

* Added support for new arguments for BITPOS, BITCOUNT commands (#1045)

* Added support for new arguments for EXPIRE, EXPIREAT commands (#1046)

* Extended core support by implementing SORT_RO command (#1044)

* Added support for SORT_RO command

* Codestyle fixes

* Added command description

---------

Co-authored-by: Vladyslav Vildanov <vladyslavvildanov@Vladyslav-Vildanov-MacBook-Pro.local>

* fix deprecated call

* Added support for container commands (#1049)

* Added support for container commands FUNCTION LOAD, FUNCTION DELETE and FCALL

* Changed ContainerInterface and AbstractContainer

* Re-implement logic of abstract methods

---------

Co-authored-by: Vladyslav Vildanov <vladyslavvildanov@Vladyslav-Vildanov-MacBook-Pro.local>

* Added stream commands to KeyPrefixProcessor (#1051)

Co-authored-by: Vladyslav Vildanov <vladyslavvildanov@Vladyslav-Vildanov-MacBook-Pro.local>

* Fix return type of ReplicationInterface::getSlaves (#1111)

* Codestyle fixes

* Changed return annotation

* Added support for TS.CREATERULE command

* Added support for TS.DELETERULE command

---------

Co-authored-by: Vladyslav Vildanov <vladyslavvildanov@Vladyslav-Vildanov-MacBook-Pro.local>
Co-authored-by: Till Krüss <till@kruss.io>
Co-authored-by: Stephan <glaubinix@users.noreply.github.com>
This commit is contained in:
Vladyslav Vildanov
2023-03-29 10:39:25 +03:00
committed by GitHub
parent 4bcb599fc2
commit df29591e2f
5 changed files with 164 additions and 0 deletions
@@ -0,0 +1,37 @@
<?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.
*/
use Predis\Client;
use Predis\Command\Argument\TimeSeries\CreateArguments;
require __DIR__ . '/../../shared.php';
// Example of TS.CREATERULE command usage:
// 1. Create time series
$client = new Client();
$arguments = (new CreateArguments())
->labels('type', 'temp', 'location', 'TLV');
$createResponse = $client->tscreate('temp:TLV', $arguments);
echo "Original time series creation status: {$createResponse}\n";
$createResponse = $client->tscreate('dailyAvgTemp:TLV', $arguments);
echo "Compacted time series creation status: {$createResponse}\n";
$createRuleResponse = $client->tscreaterule('temp:TLV', 'dailyAvgTemp:TLV', 'avg', 1000);
echo "Compacted rule for compacted time series creation status: {$createRuleResponse}\n";
// 2. Remove compaction rule
$deleteRuleResponse = $client->tsdeleterule('temp:TLV', 'dailyAvgTemp:TLV');
echo "Compacted rule for compacted time series deletion status: {$deleteRuleResponse}\n";
+1
View File
@@ -247,6 +247,7 @@ use Predis\Command\Container\Search\FTCONFIG;
* @method $this tscreaterule(string $sourceKey, string $destKey, string $aggregator, int $bucketDuration, int $alignTimestamp = 0)
* @method $this tsdecrby(string $key, float $value, ?DecrByArguments $arguments = null)
* @method $this tsdel(string $key, int $fromTimestamp, int $toTimestamp)
* @method $this tsdeleterule(string $sourceKey, string $destKey)
* @method $this tsget(string $key, GetArguments $arguments = null)
* @method $this tsincrby(string $key, float $value, ?IncrByArguments $arguments = null)
* @method $this tsinfo(string $key, ?InfoArguments $arguments = null)
+1
View File
@@ -257,6 +257,7 @@ use Predis\Response\Status;
* @method Status tscreaterule(string $sourceKey, string $destKey, string $aggregator, int $bucketDuration, int $alignTimestamp = 0)
* @method int tsdecrby(string $key, float $value, ?DecrByArguments $arguments = null)
* @method int tsdel(string $key, int $fromTimestamp, int $toTimestamp)
* @method Status tsdeleterule(string $sourceKey, string $destKey)
* @method array tsget(string $key, GetArguments $arguments = null)
* @method int tsincrby(string $key, float $value, ?IncrByArguments $arguments = null)
* @method array tsinfo(string $key, ?InfoArguments $arguments = null)
@@ -0,0 +1,28 @@
<?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\Command as RedisCommand;
/**
* @see https://redis.io/commands/ts.deleterule/
*
* Delete a compaction rule.
*/
class TSDELETERULE extends RedisCommand
{
public function getId()
{
return 'TS.DELETERULE';
}
}
@@ -0,0 +1,97 @@
<?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\Redis\PredisCommandTestCase;
use Predis\Response\ServerException;
class TSDELETERULE_Test extends PredisCommandTestCase
{
/**
* {@inheritDoc}
*/
protected function getExpectedCommand(): string
{
return TSDELETERULE::class;
}
/**
* {@inheritDoc}
*/
protected function getExpectedId(): string
{
return 'TSDELETERULE';
}
/**
* @group disconnected
*/
public function testFilterArguments(): void
{
$actualArguments = ['sourceKey', 'destKey'];
$expectedArguments = ['sourceKey', 'destKey'];
$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
* @return void
* @requiresRedisTimeSeriesVersion >= 1.0.0
*/
public function testDeleteCompactionRuleFromGivenTimeSeries(): void
{
$redis = $this->getClient();
$arguments = (new CreateArguments())
->labels('type', 'temp', 'location', 'TLV');
$this->assertEquals('OK', $redis->tscreate('temp:TLV', $arguments));
$this->assertEquals('OK', $redis->tscreate('dailyAvgTemp:TLV', $arguments));
$this->assertEquals(
'OK',
$redis->tscreaterule('temp:TLV', 'dailyAvgTemp:TLV', 'twa', 86400000)
);
$this->assertEquals(
'OK',
$redis->tsdeleterule('temp:TLV', 'dailyAvgTemp:TLV')
);
}
/**
* @group connected
* @return void
* @requiresRedisTimeSeriesVersion >= 1.0.0
*/
public function testThrowsExceptionOnNonExistingDestinationKey(): void
{
$redis = $this->getClient();
$this->expectException(ServerException::class);
$this->expectExceptionMessage('ERR TSDB: the key does not exist');
$redis->tsdeleterule('temp:TLV', 'dailyAvgTemp:TLV');
}
}