From 62051efdbcd8c9d5298177c76f269f648dbf6300 Mon Sep 17 00:00:00 2001 From: agustin18 Date: Thu, 19 Nov 2026 19:49:52 +0000 Subject: [PATCH] fix(cli): list indices through SearchIndex.listall() `rvl index listall` called `FT._LIST` directly, so it failed on a Redis Cluster: the command has no key, and the client cannot pick a node for it. Delegate to `list_indexes()`, which builds a placeholder index and calls `SearchIndex.listall()`. That method already sends the keyless `FT._LIST` to the default node, so the CLI keeps no copy of the routing. The RESP3 set handling goes with it: redis-py's RESP3 parser returns `~` replies as lists, and RedisVL talks protocol 2. --- redisvl/cli/index.py | 10 +++------- tests/unit/test_cli_index.py | 27 ++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/redisvl/cli/index.py b/redisvl/cli/index.py index 888b35aa..9e0a2701 100644 --- a/redisvl/cli/index.py +++ b/redisvl/cli/index.py @@ -13,11 +13,8 @@ ) from redisvl.exceptions import RedisSearchError from redisvl.index import SearchIndex -from redisvl.redis.connection import ( - RedisConnectionFactory, - normalize_index_definition, - normalize_index_fields, -) +from redisvl.migration.utils import list_indexes +from redisvl.redis.connection import normalize_index_definition, normalize_index_fields from redisvl.redis.utils import convert_bytes from redisvl.schema.schema import IndexSchema @@ -223,8 +220,7 @@ def listall(self, args: Namespace): rvl index listall [--json] """ redis_url = create_redis_url(args) - conn = RedisConnectionFactory.get_redis_connection(redis_url=redis_url) - indices = convert_bytes(conn.execute_command("FT._LIST")) + indices = list_indexes(redis_url=redis_url) if args.json: cli_print_json({"indices": indices}) else: diff --git a/tests/unit/test_cli_index.py b/tests/unit/test_cli_index.py index b38d7b39..4fcfee42 100644 --- a/tests/unit/test_cli_index.py +++ b/tests/unit/test_cli_index.py @@ -7,6 +7,7 @@ from unittest.mock import MagicMock import pytest +from redis.cluster import RedisCluster from redisvl.cli.index import Index, _display_in_table, _index_info_for_json from redisvl.exceptions import RedisSearchError @@ -173,6 +174,30 @@ def test_listall_json(monkeypatch, capsys, redis_url, cli_index): assert captured.err == "" +def test_listall_cluster_targets_default_node(monkeypatch, capsys): + """On a Redis Cluster, the CLI lists indices through the default node.""" + conn = MagicMock(spec=RedisCluster) + node = MagicMock() + conn.get_default_node.return_value = node + conn.execute_command.return_value = [b"idx"] + monkeypatch.setattr( + "redisvl.migration.utils.RedisConnectionFactory.get_redis_connection", + MagicMock(return_value=conn), + ) + monkeypatch.setattr( + sys, + "argv", + ["rvl", "index", "listall", "--json", "--url", "redis://localhost:6379"], + ) + + Index() + captured = capsys.readouterr() + + conn.execute_command.assert_called_once_with("FT._LIST", target_nodes=node) + assert json.loads(captured.out.strip()) == {"indices": ["idx"]} + assert captured.err == "" + + def test_info_json_normalize(): """Tests that ``_index_info_for_json`` maps FT.INFO lists to structured JSON. @@ -446,7 +471,7 @@ def test_index_runtime_errors( ) elif patch_target == "listall": monkeypatch.setattr( - "redisvl.cli.index.RedisConnectionFactory.get_redis_connection", + "redisvl.migration.utils.RedisConnectionFactory.get_redis_connection", MagicMock(side_effect=error), ) elif patch_target == "info":