Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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
7 changes: 4 additions & 3 deletions redis/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -1525,11 +1525,12 @@ def initialize(self):
)
self.startup_nodes[startup_node.name].redis_connection = r
# Make sure cluster mode is enabled on this node
if bool(r.info().get("cluster_enabled")) is False:
try:
cluster_slots = str_if_bytes(r.execute_command("CLUSTER SLOTS"))
except ResponseError as e:
raise RedisClusterException(
"Cluster mode is not enabled on this node"
"Cluster mode is not enabled on this node."
)
cluster_slots = str_if_bytes(r.execute_command("CLUSTER SLOTS"))
startup_nodes_reachable = True
except Exception as e:
# Try the next startup node.
Expand Down
14 changes: 10 additions & 4 deletions tests/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def cleanup():
r.config_set("slowlog-max-len", 128)


def get_mocked_redis_client(func=None, *args, **kwargs):
def get_mocked_redis_client(func=None, cluster_slots_raise_error=False, *args, **kwargs):
"""
Return a stable RedisCluster object that have deterministic
nodes and slots setup to remove the problem of different IP addresses
Expand All @@ -164,8 +164,11 @@ def get_mocked_redis_client(func=None, *args, **kwargs):

def execute_command(*_args, **_kwargs):
if _args[0] == "CLUSTER SLOTS":
mock_cluster_slots = cluster_slots
return mock_cluster_slots
if cluster_slots_raise_error:
raise ResponseError()
else:
mock_cluster_slots = cluster_slots
return mock_cluster_slots
elif _args[0] == "COMMAND":
return {"get": [], "set": []}
elif _args[0] == "INFO":
Expand Down Expand Up @@ -2654,7 +2657,10 @@ def test_init_slots_cache_cluster_mode_disabled(self):
"""
with pytest.raises(RedisClusterException) as e:
get_mocked_redis_client(
host=default_host, port=default_port, cluster_enabled=False
cluster_slots_raise_error=True,
host=default_host,
port=default_port,
cluster_enabled=False
)
assert "Cluster mode is not enabled on this node" in str(e.value)

Expand Down