11import itertools
22import time
3- from typing import Any , Dict , List , Optional , Union
3+ from typing import Any , Dict , List , Optional , Set , Union
44
55from redis ._parsers .helpers import pairs_to_dict
66from redis .client import NEVER_DECODE , Pipeline
1111 HybridQuery ,
1212)
1313from redis .commands .search .hybrid_result import HybridCursorResult , HybridResult
14+ from redis .typing import KeyT
1415from redis .utils import (
1516 check_protocol_version ,
1617 decode_field_value ,
5758ALIAS_ADD_CMD = "FT.ALIASADD"
5859ALIAS_UPDATE_CMD = "FT.ALIASUPDATE"
5960ALIAS_DEL_CMD = "FT.ALIASDEL"
61+ ALIAS_LIST_CMD = "FT.ALIASLIST"
6062INFO_CMD = "FT.INFO"
6163SUGADD_COMMAND = "FT.SUGADD"
6264SUGDEL_COMMAND = "FT.SUGDEL"
@@ -109,6 +111,7 @@ def _init_module_callbacks(self):
109111 SPELLCHECK_CMD : self ._parse_spellcheck ,
110112 CONFIG_CMD : self ._parse_config_get ,
111113 SYNDUMP_CMD : self ._parse_syndump ,
114+ ALIAS_LIST_CMD : self ._parse_aliaslist ,
112115 }
113116 # Explicit ``protocol=3`` + ``legacy_responses=True`` keeps the
114117 # pre-existing native RESP3 surface. SEARCH and HYBRID both use
@@ -119,6 +122,7 @@ def _init_module_callbacks(self):
119122 self ._RESP3_MODULE_CALLBACKS = {
120123 SEARCH_CMD : self ._parse_search_resp3_native ,
121124 HYBRID_CMD : self ._parse_hybrid_search_resp3_native ,
125+ ALIAS_LIST_CMD : self ._parse_aliaslist ,
122126 }
123127 # ``protocol=None`` + ``legacy_responses=True`` (the v8 default):
124128 # the wire is RESP3 but the Python surface mirrors RESP2 legacy
@@ -133,6 +137,7 @@ def _init_module_callbacks(self):
133137 SPELLCHECK_CMD : self ._parse_spellcheck_resp3 ,
134138 CONFIG_CMD : self ._parse_config_get_resp3_to_legacy ,
135139 SYNDUMP_CMD : self ._parse_syndump_resp3 ,
140+ ALIAS_LIST_CMD : self ._parse_aliaslist ,
136141 }
137142 # Search pipelines historically returned raw wire responses in
138143 # legacy mode. The default connection now uses RESP3 on the wire,
@@ -141,6 +146,14 @@ def _init_module_callbacks(self):
141146 self ._RESP3_TO_RESP2_LEGACY_PIPELINE_CALLBACKS = {
142147 SEARCH_CMD : self ._pipeline_parse_search_resp3_to_legacy ,
143148 HYBRID_CMD : self ._pipeline_parse_hybrid_search_resp3_to_legacy ,
149+ ALIAS_LIST_CMD : self ._parse_aliaslist ,
150+ }
151+ # ``protocol=2`` + ``legacy_responses=True`` pipelines otherwise return
152+ # raw wire responses. ``FT.ALIASLIST`` is a new command with no pre-v8
153+ # raw pipeline shape to preserve, so it is still normalized to a ``set``
154+ # to match the direct-call behavior and the documented return type.
155+ self ._RESP2_LEGACY_PIPELINE_CALLBACKS = {
156+ ALIAS_LIST_CMD : self ._parse_aliaslist ,
144157 }
145158 # ``legacy_responses=False`` + RESP2 wire: enhanced RESP2 parsers
146159 # producing the unified shape (``attributes`` as list of dicts,
@@ -155,6 +168,7 @@ def _init_module_callbacks(self):
155168 SPELLCHECK_CMD : self ._parse_spellcheck ,
156169 CONFIG_CMD : self ._parse_config_get_unified ,
157170 SYNDUMP_CMD : self ._parse_syndump_unified ,
171+ ALIAS_LIST_CMD : self ._parse_aliaslist ,
158172 }
159173 # ``legacy_responses=False`` + RESP3 wire: keeps the native RESP3
160174 # shape for commands whose unified shape diverges from the
@@ -261,6 +275,16 @@ def _parse_info(self, res, **kwargs):
261275 it = map (str_if_bytes , res )
262276 return dict (zip (it , it ))
263277
278+ def _parse_aliaslist (self , res , ** kwargs ):
279+ # RESP2 replies with an array and RESP3 with a set; both are decoded
280+ # into a list/set by the parsers, so normalize to an unordered ``set``.
281+ # Alias names are user data, so they honor ``decode_responses`` (``str``
282+ # when decoding is enabled, ``bytes`` when it is not) — matching the
283+ # passthrough behavior of FT.TAGVALS and FT.DICTDUMP rather than being
284+ # force-decoded like the structural map keys handled by the other
285+ # search parsers.
286+ return set (res ) if res else set ()
287+
264288 def _parse_search (self , res , ** kwargs ):
265289 return Result (
266290 res ,
@@ -1611,7 +1635,7 @@ def tagvals(self, tagfield: str):
16111635
16121636 return self .execute_command (TAGVALS_CMD , self .index_name , tagfield )
16131637
1614- def aliasadd (self , alias : str ):
1638+ def aliasadd (self , alias : KeyT ):
16151639 """
16161640 Alias a search index - will fail if alias already exists
16171641
@@ -1624,7 +1648,7 @@ def aliasadd(self, alias: str):
16241648
16251649 return self .execute_command (ALIAS_ADD_CMD , alias , self .index_name )
16261650
1627- def aliasupdate (self , alias : str ):
1651+ def aliasupdate (self , alias : KeyT ):
16281652 """
16291653 Updates an alias - will fail if alias does not already exist
16301654
@@ -1637,7 +1661,7 @@ def aliasupdate(self, alias: str):
16371661
16381662 return self .execute_command (ALIAS_UPDATE_CMD , alias , self .index_name )
16391663
1640- def aliasdel (self , alias : str ):
1664+ def aliasdel (self , alias : KeyT ):
16411665 """
16421666 Removes an alias to a search index
16431667
@@ -1649,6 +1673,23 @@ def aliasdel(self, alias: str):
16491673 """ # noqa
16501674 return self .execute_command (ALIAS_DEL_CMD , alias )
16511675
1676+ def aliaslist (self ) -> Set [str | bytes ]:
1677+ """
1678+ List all aliases associated with the current index as an unordered set.
1679+
1680+ The index must be the name of an index created with ``FT.CREATE``; an
1681+ alias name is not accepted as a substitute. Returns an empty set when
1682+ the index exists but has no aliases. Alias names honor
1683+ ``decode_responses`` (``str`` when decoding is enabled, ``bytes``
1684+ otherwise).
1685+
1686+ For more information see `FT.ALIASLIST <https://redis.io/commands/ft.aliaslist>`_.
1687+ """ # noqa
1688+ res = self .execute_command (ALIAS_LIST_CMD , self .index_name )
1689+ if isinstance (res , Pipeline ):
1690+ return res
1691+ return self ._parse_results (ALIAS_LIST_CMD , res )
1692+
16521693 def sugadd (self , key , * suggestions , ** kwargs ):
16531694 """
16541695 Add suggestion terms to the AutoCompleter engine. Each suggestion has
@@ -1794,6 +1835,23 @@ async def info(self):
17941835 res = await self .execute_command (INFO_CMD , self .index_name )
17951836 return self ._parse_results (INFO_CMD , res )
17961837
1838+ async def aliaslist (self ) -> Set [str | bytes ]:
1839+ """
1840+ List all aliases associated with the current index as an unordered set.
1841+
1842+ The index must be the name of an index created with ``FT.CREATE``; an
1843+ alias name is not accepted as a substitute. Returns an empty set when
1844+ the index exists but has no aliases. Alias names honor
1845+ ``decode_responses`` (``str`` when decoding is enabled, ``bytes``
1846+ otherwise).
1847+
1848+ For more information see `FT.ALIASLIST <https://redis.io/commands/ft.aliaslist>`_.
1849+ """ # noqa
1850+ res = await self .execute_command (ALIAS_LIST_CMD , self .index_name )
1851+ if isinstance (res , Pipeline ):
1852+ return res
1853+ return self ._parse_results (ALIAS_LIST_CMD , res )
1854+
17971855 async def search (
17981856 self ,
17991857 query : Union [str , Query ],
0 commit comments