mirror of
https://github.com/predis/predis.git
synced 2026-09-15 12:57:10 +00:00
Extended RediSearch support by implementing FT.ALIASUPDATE command (#1152)
* 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 support for FT.ALIASUPDATE command * 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:
committed by
GitHub
parent
fcf1c8c59a
commit
329f8f8d4d
@@ -89,6 +89,7 @@ use Predis\Command\Redis\Container\FUNCTIONS;
|
||||
* @method $this fcall(string $function, array $keys, ...$args)
|
||||
* @method $this ftaliasadd(string $alias, string $index)
|
||||
* @method $this ftaliasdel(string $alias)
|
||||
* @method $this ftaliasupdate(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)
|
||||
|
||||
@@ -98,6 +98,7 @@ use Predis\Response\Status;
|
||||
* @method mixed fcall(string $function, array $keys, ...$args)
|
||||
* @method Status ftaliasadd(string $alias, string $index)
|
||||
* @method Status ftaliasdel(string $alias)
|
||||
* @method Status ftaliasupdate(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)
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?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.aliasupdate/
|
||||
*
|
||||
* Add an alias to an index. If the alias is already associated with another index,
|
||||
* FT.ALIASUPDATE removes the alias association with the previous index.
|
||||
*/
|
||||
class FTALIASUPDATE extends RedisCommand
|
||||
{
|
||||
public function getId()
|
||||
{
|
||||
return 'FT.ALIASUPDATE';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
<?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\Schema;
|
||||
use Predis\Command\Redis\PredisCommandTestCase;
|
||||
use Predis\Response\ServerException;
|
||||
|
||||
class FTALIASUPDATE_Test extends PredisCommandTestCase
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getExpectedCommand(): string
|
||||
{
|
||||
return FTALIASUPDATE::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getExpectedId(): string
|
||||
{
|
||||
return 'FTALIASUPDATE';
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 testUpdateAliasAddAliasToGivenIndexIfAliasNotExists(): void
|
||||
{
|
||||
$redis = $this->getClient();
|
||||
|
||||
$schema = new Schema();
|
||||
$schema->addTextField('text_field');
|
||||
|
||||
$createResponse = $redis->ftcreate('index', $schema);
|
||||
$this->assertEquals('OK', $createResponse);
|
||||
|
||||
$actualResponse = $redis->ftaliasupdate('alias', 'index');
|
||||
$this->assertEquals('OK', $actualResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @return void
|
||||
* @requiresRediSearchVersion >= 1.0.0
|
||||
*/
|
||||
public function testUpdateRemovesAliasAssociationFromAlreadyExistingAlias(): void
|
||||
{
|
||||
$redis = $this->getClient();
|
||||
|
||||
$schema = new Schema();
|
||||
$schema->addTextField('text_field');
|
||||
|
||||
$createResponse = $redis->ftcreate('index', $schema);
|
||||
$this->assertEquals('OK', $createResponse);
|
||||
|
||||
$actualResponse = $redis->ftaliasadd('alias', 'index');
|
||||
$this->assertEquals('OK', $actualResponse);
|
||||
$this->assertEquals('OK', $redis->ftaliasupdate('new_alias', 'index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @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->ftaliasupdate('alias', 'index');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user