mirror of
https://github.com/predis/predis.git
synced 2026-08-31 04:35:05 +00:00
Extended TDigest Sketch support by implementing TDIGEST.ADD command (#1094)
* Added support for TDIGEST.ADD command * Codestyle fixes --------- Co-authored-by: Vladyslav Vildanov <vladyslavvildanov@Vladyslav-Vildanov-MacBook-Pro.local>
This commit is contained in:
committed by
GitHub
parent
43ecf3f4fb
commit
cf539f9ea7
@@ -173,6 +173,7 @@ use Predis\Command\CommandInterface;
|
||||
* @method $this sscan($key, $cursor, array $options = null)
|
||||
* @method $this sunion(array|string $keys)
|
||||
* @method $this sunionstore($destination, array|string $keys)
|
||||
* @method $this tdigestadd(string $key, float ...$value)
|
||||
* @method $this tdigestcreate(string $key, int $compression = 0)
|
||||
* @method $this tdigestinfo(string $key)
|
||||
* @method $this zadd($key, array $membersAndScoresDictionary)
|
||||
|
||||
@@ -183,6 +183,7 @@ use Predis\Response\Status;
|
||||
* @method string[] sunion(array|string $keys)
|
||||
* @method int sunionstore(string $destination, array|string $keys)
|
||||
* @method int touch(string[]|string $keyOrKeys, string ...$keys = null)
|
||||
* @method Status tdigestadd(string $key, float ...$value)
|
||||
* @method Status tdigestcreate(string $key, int $compression = 0)
|
||||
* @method array tdigestinfo(string $key)
|
||||
* @method string xadd(string $key, array $dictionary, string $id = '*', array $options = 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\TDigest;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see https://redis.io/commands/tdigest.add/
|
||||
*
|
||||
* Adds one or more observations to a t-digest sketch.
|
||||
*/
|
||||
class TDIGESTADD extends RedisCommand
|
||||
{
|
||||
public function getId()
|
||||
{
|
||||
return 'TDIGEST.ADD';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?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\TDigest;
|
||||
|
||||
use Predis\Command\Redis\PredisCommandTestCase;
|
||||
use Predis\Response\ServerException;
|
||||
|
||||
class TDIGESTADD_Test extends PredisCommandTestCase
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getExpectedCommand(): string
|
||||
{
|
||||
return TDIGESTADD::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getExpectedId(): string
|
||||
{
|
||||
return 'TDIGESTADD';
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testFilterArguments(): void
|
||||
{
|
||||
$actualArguments = ['key', 1, 2, 3];
|
||||
$expectedArguments = ['key', 1, 2, 3];
|
||||
|
||||
$command = $this->getCommand();
|
||||
$command->setArguments($actualArguments);
|
||||
|
||||
$this->assertSameValues($expectedArguments, $command->getArguments());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @return void
|
||||
* @requiresRedisBfVersion >= 2.4.0
|
||||
*/
|
||||
public function testAddObservationsIntoGivenTDigestSketch(): void
|
||||
{
|
||||
$redis = $this->getClient();
|
||||
|
||||
$redis->tdigestcreate('key');
|
||||
|
||||
$actualResponse = $redis->tdigestadd('key', 1, 2, 3);
|
||||
$info = $redis->tdigestinfo('key');
|
||||
|
||||
$this->assertEquals('OK', $actualResponse);
|
||||
$this->assertSame(3, $info['Observations']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @return void
|
||||
* @requiresRedisBfVersion >= 2.4.0
|
||||
*/
|
||||
public function testThrowsExceptionOnNonExistingTDigestSketch(): void
|
||||
{
|
||||
$redis = $this->getClient();
|
||||
|
||||
$this->expectException(ServerException::class);
|
||||
$this->expectExceptionMessage('ERR T-Digest: key does not exist');
|
||||
|
||||
$redis->tdigestadd('key', 1, 2, 3);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user