From 16844693029d19867dd78df6300a29b2b1a6bafa Mon Sep 17 00:00:00 2001 From: Vladyslav Vildanov <117659936+vladvildanov@users.noreply.github.com> Date: Thu, 23 Feb 2023 14:33:41 +0200 Subject: [PATCH] Extended RediSearch support by implementing FT.DICTDEL support (#1156) * add support for CF.ADDNX * fix key name * fix wrong command * Pulling changes * Added support for FT.CREATE command * Fixed tests to choose correct DB * Added test coverage * Revert changes for missing commands * Added data types enums, added methods default assignments * Fixed vector field, removed default assignments, fixed tests * Added constants enum for Sortable argument, renamed arguments object * Codestyle fixes * Rename test class * Added support for FT.DICTADD command * Added support for FT.DICTDEL command --------- Co-authored-by: shacharPash Co-authored-by: Vladyslav Vildanov --- src/ClientContextInterface.php | 1 + src/ClientInterface.php | 1 + src/Command/Redis/Search/FTDICTDEL.php | 28 ++++++ .../Command/Redis/Search/FTDICTDEL_Test.php | 98 +++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 src/Command/Redis/Search/FTDICTDEL.php create mode 100644 tests/Predis/Command/Redis/Search/FTDICTDEL_Test.php diff --git a/src/ClientContextInterface.php b/src/ClientContextInterface.php index 02a1184f..1d49b2f7 100644 --- a/src/ClientContextInterface.php +++ b/src/ClientContextInterface.php @@ -92,6 +92,7 @@ use Predis\Command\Redis\Container\FUNCTIONS; * @method $this ftaliasupdate(string $alias, string $index) * @method $this ftcreate(string $index, Schema $schema, ?CreateArguments $arguments = null) * @method $this ftdictadd(string $dict, ...$term) + * @method $this ftdictdel(string $dict, ...$term) * @method $this ftinfo(string $index) * @method $this ftsearch(string $index, string $query, ?SearchArguments $arguments = null) * @method $this get($key) diff --git a/src/ClientInterface.php b/src/ClientInterface.php index 1da2f51b..2c4e29bf 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -101,6 +101,7 @@ use Predis\Response\Status; * @method Status ftaliasupdate(string $alias, string $index) * @method Status ftcreate(string $index, Schema $schema, ?CreateArguments $arguments = null) * @method int ftdictadd(string $dict, ...$term) + * @method int ftdictdel(string $dict, ...$term) * @method array ftinfo(string $index) * @method array ftsearch(string $index, string $query, ?SearchArguments $arguments = null) * @method string|null get(string $key) diff --git a/src/Command/Redis/Search/FTDICTDEL.php b/src/Command/Redis/Search/FTDICTDEL.php new file mode 100644 index 00000000..19e0633b --- /dev/null +++ b/src/Command/Redis/Search/FTDICTDEL.php @@ -0,0 +1,28 @@ +getCommand(); + $command->setArguments($actualArguments); + + $this->assertSameValues($expectedArguments, $command->getArguments()); + } + + /** + * @group disconnected + */ + public function testParseResponse(): void + { + $this->assertSame(1, $this->getCommand()->parseResponse(1)); + } + + /** + * @group connected + * @dataProvider dictionariesProvider + * @param array $addArguments + * @param array $deleteArguments + * @param int $expectedResponse + * @return void + * @requiresRediSearchVersion >= 1.4.0 + */ + public function testRemovesTermsFromGivenDictionary( + array $addArguments, + array $deleteArguments, + int $expectedResponse + ): void { + $redis = $this->getClient(); + + $redis->ftdictadd(...$addArguments); + + $this->assertSame($expectedResponse, $redis->ftdictdel(...$deleteArguments)); + } + + public function dictionariesProvider(): array + { + return [ + 'removes existing term' => [ + ['dict', 'foo', 'bar'], + ['dict', 'foo'], + 1, + ], + 'removes non-existing term' => [ + ['dict', 'foo', 'bar'], + ['dict', 'baz'], + 0, + ], + 'removes from non-existing dict' => [ + ['dict', 'foo', 'bar'], + ['dict123', 'baz'], + 0, + ], + ]; + } +}