Extended RediSearch support by implementing FT.SUGLEN command (#1186)

* 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 FT.SUGLEN 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-01 13:19:19 +02:00
committed by GitHub
parent 5a9f62ef78
commit 00a8e5cd61
6 changed files with 105 additions and 2 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
[codespell]
skip=./.git,./src/Command/Redis/Search/FTSUGGET.php,./examples/Commands/Search/ft_sug_add_get_del.php
skip=./.git,./src/Command/Redis/Search/FTSUGGET.php,./examples/Commands/Search/ft_sug_add_get_del_len.php
check-hidden=
check-filenames=
builtin=clear,rare,informal,usage,code,names
@@ -16,13 +16,15 @@ use Predis\Command\Argument\Search\SugGetArguments;
require __DIR__ . '/../../shared.php';
// Example of FT.SUGADD, FT.SUGGET, FT.SUGDEL commands usage:
// Example of FT.SUGADD, FT.SUGGET, FT.SUGDEL, FT.SUGLEN commands usage:
// 1. Add suggestion to key with payload
$client = new Client();
$client->ftsugadd('key', 'hello', 2, (new SugAddArguments())->payload('payload'));
echo 'Suggestions dictionary length: ' . $client->ftsuglen('key') . "\n";
// 2. Perform fuzzy search by prefix to get previous suggestion with payload
$response = $client->ftsugget('key', 'hellp', (new SugGetArguments())->fuzzy()->withPayloads());
+1
View File
@@ -111,6 +111,7 @@ use Predis\Command\Container\Search\FTCONFIG;
* @method $this ftsugadd(string $key, string $string, float $score, ?SugAddArguments $arguments = null)
* @method $this ftsugdel(string $key, string $string)
* @method $this ftsugget(string $key, string $prefix, ?SugGetArguments $arguments = null)
* @method $this ftsuglen(string $key)
* @method $this ftsyndump(string $index)
* @method $this ftsynupdate(string $index, string $synonymGroupId, ?SynUpdateArguments $arguments = null, string ...$terms)
* @method $this fttagvals(string $index, string $fieldName)
+1
View File
@@ -120,6 +120,7 @@ use Predis\Response\Status;
* @method int ftsugadd(string $key, string $string, float $score, ?SugAddArguments $arguments = null)
* @method int ftsugdel(string $key, string $string)
* @method array ftsugget(string $key, string $prefix, ?SugGetArguments $arguments = null)
* @method int ftsuglen(string $key)
* @method array ftsyndump(string $index)
* @method Status ftsynupdate(string $index, string $synonymGroupId, ?SynUpdateArguments $arguments = null, string ...$terms)
* @method array fttagvals(string $index, string $fieldName)
+28
View File
@@ -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\Search;
use Predis\Command\Command as RedisCommand;
/**
* @see https://redis.io/commands/ft.suglen/
*
* Get the size of an auto-complete suggestion dictionary.
*/
class FTSUGLEN extends RedisCommand
{
public function getId()
{
return 'FT.SUGLEN';
}
}
@@ -0,0 +1,71 @@
<?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\Search;
use Predis\Command\Redis\PredisCommandTestCase;
class FTSUGLEN_Test extends PredisCommandTestCase
{
/**
* {@inheritDoc}
*/
protected function getExpectedCommand(): string
{
return FTSUGLEN::class;
}
/**
* {@inheritDoc}
*/
protected function getExpectedId(): string
{
return 'FTSUGLEN';
}
/**
* @group disconnected
*/
public function testFilterArguments(): void
{
$actualArguments = ['key'];
$expectedArguments = ['key'];
$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
* @requiresRediSearchVersion >= 1.0.0
*/
public function testReturnsLengthOfGivenSuggestionDictionary(): void
{
$redis = $this->getClient();
$redis->ftsugadd('key', 'foo', 1);
$redis->ftsugadd('key', 'bar', 1);
$this->assertSame(2, $redis->ftsuglen('key'));
}
}