From 96c634ef909ff6fdd04f88a39367c83d7bde8932 Mon Sep 17 00:00:00 2001 From: Vladyslav Vildanov <117659936+vladvildanov@users.noreply.github.com> Date: Tue, 21 Jul 2026 11:00:18 +0300 Subject: [PATCH] Added support for FT.ALIASLIST command (#1705) --- CHANGELOG.md | 1 + src/ClientContextInterface.php | 1 + src/ClientInterface.php | 1 + src/Command/Redis/Search/FTALIASLIST.php | 33 +++++ .../Command/Redis/Search/FTALIASLIST_Test.php | 128 ++++++++++++++++++ 5 files changed, 164 insertions(+) create mode 100644 src/Command/Redis/Search/FTALIASLIST.php create mode 100644 tests/Predis/Command/Redis/Search/FTALIASLIST_Test.php diff --git a/CHANGELOG.md b/CHANGELOG.md index bc82953e..324628c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Added support for `TS.READ` command - Added support for `EXCLUDEEMPTY` argument for `TS.MRANGE` and `TS.MREVRANGE` commands - Added explicit testing for FT.SEARCH timeout policies +- Added support for `FT.ALIASLIST` command ### Fixed - Fixed Sentinel does not wipe servers on exception caused (#1694) diff --git a/src/ClientContextInterface.php b/src/ClientContextInterface.php index 503d18ea..306fc07e 100644 --- a/src/ClientContextInterface.php +++ b/src/ClientContextInterface.php @@ -144,6 +144,7 @@ use Predis\Command\Redis\VADD; * @method $this ftaggregate(string $index, string $query, ?AggregateArguments $arguments = null) * @method $this ftaliasadd(string $alias, string $index) * @method $this ftaliasdel(string $alias) + * @method $this ftaliaslist(string $index) * @method $this ftaliasupdate(string $alias, string $index) * @method $this ftalter(string $index, FieldInterface[] $schema, ?AlterArguments $arguments = null) * @method $this ftcreate(string $index, FieldInterface[] $schema, ?CreateArguments $arguments = null) diff --git a/src/ClientInterface.php b/src/ClientInterface.php index 393f7eb6..dd2ba66b 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -155,6 +155,7 @@ use Predis\Response\Status; * @method array ftaggregate(string $index, string $query, ?AggregateArguments $arguments = null) * @method Status ftaliasadd(string $alias, string $index) * @method Status ftaliasdel(string $alias) + * @method array ftaliaslist(string $index) * @method Status ftaliasupdate(string $alias, string $index) * @method Status ftalter(string $index, FieldInterface[] $schema, ?AlterArguments $arguments = null) * @method Status ftcreate(string $index, FieldInterface[] $schema, ?CreateArguments $arguments = null) diff --git a/src/Command/Redis/Search/FTALIASLIST.php b/src/Command/Redis/Search/FTALIASLIST.php new file mode 100644 index 00000000..c041d3ce --- /dev/null +++ b/src/Command/Redis/Search/FTALIASLIST.php @@ -0,0 +1,33 @@ +applyPrefixForFirstArgument($prefix); + } +} diff --git a/tests/Predis/Command/Redis/Search/FTALIASLIST_Test.php b/tests/Predis/Command/Redis/Search/FTALIASLIST_Test.php new file mode 100644 index 00000000..aaad54d2 --- /dev/null +++ b/tests/Predis/Command/Redis/Search/FTALIASLIST_Test.php @@ -0,0 +1,128 @@ +getCommand(); + $command->setArguments($actualArguments); + + $this->assertSameValues($expectedArguments, $command->getArguments()); + } + + /** + * @group disconnected + */ + public function testParseResponse(): void + { + $response = ['alias1', 'alias2']; + + $this->assertSame($response, $this->getCommand()->parseResponse($response)); + } + + /** + * @group connected + * @group relay-resp3 + * @return void + * @requiresRedisVersion >= 8.10.0 + */ + public function testReturnsAliasesAssociatedWithGivenIndex(): void + { + $redis = $this->getClient(); + + $this->assertEquals('OK', $redis->ftcreate('index', [new TextField('field')])); + $this->assertEquals('OK', $redis->ftaliasadd('alias1', 'index')); + $this->assertEquals('OK', $redis->ftaliasadd('alias2', 'index')); + + $this->assertSameValues(['alias1', 'alias2'], $redis->ftaliaslist('index')); + } + + /** + * @group connected + * @group relay-resp3 + * @return void + * @requiresRedisVersion >= 8.10.0 + */ + public function testReturnsEmptyListForIndexWithoutAliases(): void + { + $redis = $this->getClient(); + + $this->assertEquals('OK', $redis->ftcreate('index', [new TextField('field')])); + + $this->assertSame([], $redis->ftaliaslist('index')); + } + + /** + * @group connected + * @return void + * @requiresRedisVersion >= 8.10.0 + */ + public function testReturnsAliasesAssociatedWithGivenIndexResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertEquals('OK', $redis->ftcreate('index', [new TextField('field')])); + $this->assertEquals('OK', $redis->ftaliasadd('alias1', 'index')); + $this->assertEquals('OK', $redis->ftaliasadd('alias2', 'index')); + + $this->assertSameValues(['alias1', 'alias2'], $redis->ftaliaslist('index')); + } + + /** + * @group connected + * @group relay-resp3 + * @return void + * @requiresRedisVersion >= 8.10.0 + */ + public function testThrowsExceptionOnNonExistingIndex(): void + { + $redis = $this->getClient(); + + $this->expectException(ServerException::class); + $this->expectExceptionMessage('Index not found'); + + $redis->ftaliaslist('missing_index'); + } +}