mirror of
https://github.com/predis/predis.git
synced 2026-08-31 04:35:05 +00:00
Extended RediSearch support by implementing FT.INFO command (#1148)
* 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.INFO command * Codestyle fixes * 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:
committed by
GitHub
parent
7eb87c935c
commit
ee7ed2f727
@@ -88,6 +88,7 @@ use Predis\Command\Redis\Container\FUNCTIONS;
|
||||
* @method $this failover(?To $to = null, bool $abort = false, int $timeout = -1)
|
||||
* @method $this fcall(string $function, array $keys, ...$args)
|
||||
* @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)
|
||||
* @method $this get($key)
|
||||
* @method $this getbit($key, $offset)
|
||||
|
||||
@@ -97,6 +97,7 @@ use Predis\Response\Status;
|
||||
* @method Status failover(?To $to = null, bool $abort = false, int $timeout = -1)
|
||||
* @method mixed fcall(string $function, array $keys, ...$args)
|
||||
* @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)
|
||||
* @method string|null get(string $key)
|
||||
* @method int getbit(string $key, $offset)
|
||||
|
||||
@@ -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.info/
|
||||
*
|
||||
* Return information and statistics on the index.
|
||||
*/
|
||||
class FTINFO extends RedisCommand
|
||||
{
|
||||
public function getId()
|
||||
{
|
||||
return 'FT.INFO';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?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 FTINFO_Test extends PredisCommandTestCase
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getExpectedCommand(): string
|
||||
{
|
||||
return FTINFO::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getExpectedId(): string
|
||||
{
|
||||
return 'FTINFO';
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testFilterArguments(): void
|
||||
{
|
||||
$actualArguments = ['index'];
|
||||
$expectedArguments = ['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 testInfoReturnsInformationAboutGivenIndex(): 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->ftinfo('index');
|
||||
$this->assertEquals('index', $actualResponse[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @return void
|
||||
* @requiresRediSearchVersion >= 1.0.0
|
||||
*/
|
||||
public function testThrowsExceptionOnNonExistingIndex(): void
|
||||
{
|
||||
$redis = $this->getClient();
|
||||
|
||||
$this->expectException(ServerException::class);
|
||||
$this->expectExceptionMessage('Unknown Index name');
|
||||
|
||||
$redis->ftinfo('index');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user