mirror of
https://github.com/predis/predis.git
synced 2026-08-19 21:02:46 +00:00
Extended Bloom Filters by implementing BF.LOADCHUNK command (#890)
* Added CommandResolver, moved resolve command logic there, added ClientConfiguration object * Fixed test, added dependecies * Added resolved command to commands array * Used aggregation approach for modules * Added decorator to check Redis JSON module version * Added support for JSON.SET and JSON.GET commands * Added separate workflow for redis-stack tests * Changed docker imange name to correct one * Fixed indentation * Added test coverage for JSON.GET command * Changed module version resolving using annotations mapping * Re-written CommandResolver test * Update ClientInterface.php * Changes to CI, readme, removed unused modules from configuration * Fixed build badge URL * Refactored annotation check to be generic for each module * Added support for BF.ADD and BF.EXISTS commands * Fixed bug with incorrect tests skip * Added support for BF.SCANDUMP command * Added support for BF.LOADCHUNK command * Codestyle fixes * Sort alphabetical Co-authored-by: Vladyslav Vildanov <vladyslavvildanov@Vladyslav-Vildanov-MacBook-Pro.local> Co-authored-by: Till Krüss <tillkruss@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
87ef63e9da
commit
e20ebaf8fb
@@ -45,6 +45,7 @@ use Predis\Command\CommandInterface;
|
||||
* @method $this bfadd(string $key, $item)
|
||||
* @method $this bfexists(string $key, $item)
|
||||
* @method $this bfinfo(string $key, string $modifier = '')
|
||||
* @method $this bfloadchunk(string $key, int $iterator, $data)
|
||||
* @method $this bfmadd(string $key, ...$item)
|
||||
* @method $this bfmexists(string $key, ...$item)
|
||||
* @method $this bfreserve(string $key, float $errorRate, int $capacity, int $expansion = -1, bool $nonScaling = false)
|
||||
|
||||
@@ -54,6 +54,7 @@ use Predis\Response\Status;
|
||||
* @method int bfadd(string $key, $item)
|
||||
* @method int bfexists(string $key, $item)
|
||||
* @method array bfinfo(string $key, string $modifier = '')
|
||||
* @method Status bfloadchunk(string $key, int $iterator, $data)
|
||||
* @method array bfmadd(string $key, ...$item)
|
||||
* @method array bfmexists(string $key, ...$item)
|
||||
* @method Status bfreserve(string $key, float $errorRate, int $capacity, int $expansion = -1, bool $nonScaling = false)
|
||||
|
||||
@@ -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\BloomFilter;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see https://redis.io/commands/bf.loadchunk/
|
||||
*
|
||||
* Restores a filter previously saved using SCANDUMP. See the SCANDUMP command for example usage.
|
||||
*/
|
||||
class BFLOADCHUNK extends RedisCommand
|
||||
{
|
||||
public function getId()
|
||||
{
|
||||
return 'BF.LOADCHUNK';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?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\BloomFilter;
|
||||
|
||||
use Predis\Command\Redis\PredisCommandTestCase;
|
||||
use Predis\Response\ServerException;
|
||||
|
||||
class BFLOADCHUNK_Test extends PredisCommandTestCase
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getExpectedCommand(): string
|
||||
{
|
||||
return BFLOADCHUNK::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getExpectedId(): string
|
||||
{
|
||||
return 'BFLOADCHUNK';
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testFilterArguments(): void
|
||||
{
|
||||
$actualArguments = ['key', 1, 'data'];
|
||||
$expectedArguments = ['key', 1, 'data'];
|
||||
|
||||
$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
|
||||
* @requiresRedisBfVersion >= 1.0.0
|
||||
*/
|
||||
public function testLoadChunkSuccessfullyRestoresBloomFilter(): void
|
||||
{
|
||||
$redis = $this->getClient();
|
||||
|
||||
$redis->bfadd('key', 'item1');
|
||||
|
||||
$chunks = [];
|
||||
$iter = 0;
|
||||
|
||||
while (true) {
|
||||
[$iter, $data] = $redis->bfscandump('key', $iter);
|
||||
|
||||
if ($iter === 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
$chunks[] = [$iter, $data];
|
||||
}
|
||||
|
||||
$redis->flushall();
|
||||
|
||||
foreach ($chunks as $chunk) {
|
||||
[$iter, $data] = $chunk;
|
||||
$actualResponse = $redis->bfloadchunk('key', $iter, $data);
|
||||
|
||||
$this->assertEquals('OK', $actualResponse);
|
||||
}
|
||||
|
||||
$this->assertSame(1, $redis->bfexists('key', 'item1'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @requiresRedisBfVersion >= 1.0.0
|
||||
*/
|
||||
public function testThrowsExceptionOnWrongType(): void
|
||||
{
|
||||
$this->expectException(ServerException::class);
|
||||
$this->expectExceptionMessage('Operation against a key holding the wrong kind of value');
|
||||
|
||||
$redis = $this->getClient();
|
||||
|
||||
$redis->set('bfloadchunk_foo', 'bar');
|
||||
$redis->bfloadchunk('bfloadchunk_foo', 0, 'data');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user