Extended RediSearch support by implementing FT.ALIASADD command (#1150)

* 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

* Added support for FT.ALIASADD command

* Fixed expected exception message

* Fixed vector field, removed default assignments, fixed tests

* Added constants enum for Sortable argument, renamed arguments object

* Codestyle fixes

* Rename test class

---------

Co-authored-by: shacharPash <shachar.pashchur@redis.com>
Co-authored-by: Vladyslav Vildanov <vladyslavvildanov@Vladyslav-Vildanov-MacBook-Pro.local>
This commit is contained in:
Vladyslav Vildanov
2023-02-22 10:31:19 +02:00
committed by GitHub
parent ee7ed2f727
commit 2b129776d8
4 changed files with 155 additions and 0 deletions
+1
View File
@@ -87,6 +87,7 @@ use Predis\Command\Redis\Container\FUNCTIONS;
* @method $this decrby($key, $decrement)
* @method $this failover(?To $to = null, bool $abort = false, int $timeout = -1)
* @method $this fcall(string $function, array $keys, ...$args)
* @method $this ftaliasadd(string $alias, string $index)
* @method $this ftcreate(string $index, Schema $schema, ?CreateArguments $arguments = null)
* @method $this ftinfo(string $index)
* @method $this ftsearch(string $index, string $query, ?SearchArguments $arguments = null)
+1
View File
@@ -96,6 +96,7 @@ use Predis\Response\Status;
* @method int decrby(string $key, int $decrement)
* @method Status failover(?To $to = null, bool $abort = false, int $timeout = -1)
* @method mixed fcall(string $function, array $keys, ...$args)
* @method Status ftaliasadd(string $alias, string $index)
* @method Status ftcreate(string $index, Schema $schema, ?CreateArguments $arguments = null)
* @method array ftinfo(string $index)
* @method array ftsearch(string $index, string $query, ?SearchArguments $arguments = null)
+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.aliasadd/
*
* Add an alias to an index.
*/
class FTALIASADD extends RedisCommand
{
public function getId()
{
return 'FT.ALIASADD';
}
}
@@ -0,0 +1,125 @@
<?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\Argument\Search\CreateArguments;
use Predis\Command\Argument\Search\Schema;
use Predis\Command\Redis\PredisCommandTestCase;
use Predis\Response\ServerException;
class FTALIASADD_Test extends PredisCommandTestCase
{
/**
* {@inheritDoc}
*/
protected function getExpectedCommand(): string
{
return FTALIASADD::class;
}
/**
* {@inheritDoc}
*/
protected function getExpectedId(): string
{
return 'FTALIASADD';
}
/**
* @group disconnected
*/
public function testFilterArguments(): void
{
$actualArguments = ['alias', 'index'];
$expectedArguments = ['alias', 'index'];
$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 testAddAliasToGivenIndex(): void
{
$redis = $this->getClient();
$arguments = new CreateArguments();
$arguments->prefix(['prefix:']);
$arguments->language('english');
$schema = new Schema();
$schema->addTextField('text_field');
$createResponse = $redis->ftcreate('index', $schema, $arguments);
$this->assertEquals('OK', $createResponse);
$actualResponse = $redis->ftaliasadd('alias', 'index');
$this->assertEquals('OK', $actualResponse);
}
/**
* @group connected
* @return void
* @requiresRediSearchVersion >= 1.0.0
*/
public function testThrowsExceptionOnNonExistingIndex(): void
{
$redis = $this->getClient();
$this->expectException(ServerException::class);
$this->expectExceptionMessage('Unknown index name (or name is an alias itself)');
$redis->ftaliasadd('alias', 'index');
}
/**
* @group connected
* @return void
* @requiresRediSearchVersion >= 1.0.0
*/
public function testThrowsExceptionOnAlreadyExistingAlias(): void
{
$redis = $this->getClient();
$arguments = new CreateArguments();
$arguments->prefix(['prefix:']);
$arguments->language('english');
$schema = new Schema();
$schema->addTextField('text_field');
$createResponse = $redis->ftcreate('index', $schema, $arguments);
$this->assertEquals('OK', $createResponse);
$actualResponse = $redis->ftaliasadd('alias', 'index');
$this->assertEquals('OK', $actualResponse);
$this->expectException(ServerException::class);
$this->expectExceptionMessage('Alias already exists');
$redis->ftaliasadd('alias', 'index');
}
}