Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions redisvl/cli/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
27 changes: 26 additions & 1 deletion tests/unit/test_cli_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Comment thread
vishal-bala marked this conversation as resolved.
Resolved
"""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.

Expand Down Expand Up @@ -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":
Expand Down
Loading