From 198f2be1a53012a391216740c314a7412f976961 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 24 Oct 2024 20:13:02 +0800 Subject: [PATCH] Fix the issues with #9538 Signed-off-by: root --- api/extensions/ext_redis.py | 5 +++-- api/tests/unit_tests/core/test_model_manager.py | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/api/extensions/ext_redis.py b/api/extensions/ext_redis.py index d79bdf8b2f..410ebaf4bf 100644 --- a/api/extensions/ext_redis.py +++ b/api/extensions/ext_redis.py @@ -74,10 +74,11 @@ def init_app(app): redis_client.initialize(master) elif dify_config.REDIS_USE_CLUSTERS: startup_nodes = [ - {"host": node.split(":")[0], "port": int(node.split(":")[1])} for node in dify_config.REDIS_CLUSTERS.split(",") + {"host": node.split(":")[0], "port": int(node.split(":")[1])} + for node in dify_config.REDIS_CLUSTERS.split(",") ] nodes = [ClusterNode(host=node["host"], port=node["port"]) for node in startup_nodes] - redis_client.initialize(RedisCluster(startup_nodes=nodes,password=dify_config.REDIS_CLUSTERS_PASSWORD)) + redis_client.initialize(RedisCluster(startup_nodes=nodes, password=dify_config.REDIS_CLUSTERS_PASSWORD)) else: redis_params.update( { diff --git a/api/tests/unit_tests/core/test_model_manager.py b/api/tests/unit_tests/core/test_model_manager.py index 2808b5b0fa..b311baf42c 100644 --- a/api/tests/unit_tests/core/test_model_manager.py +++ b/api/tests/unit_tests/core/test_model_manager.py @@ -1,6 +1,8 @@ from unittest.mock import MagicMock import pytest +import redis +from api.extensions.ext_redis import RedisClientWrapper from core.entities.provider_entities import ModelLoadBalancingConfiguration from core.model_manager import LBModelManager @@ -55,6 +57,10 @@ def test_lb_model_manager_fetch_next(mocker, lb_model_manager): start_index += 1 return start_index + fake_redis_client = redis.Redis(host="localhost", port=6379, db=0) + redis_client = RedisClientWrapper() + redis_client.initialize(fake_redis_client) + mocker.patch("redis.Redis.incr", side_effect=incr) mocker.patch("redis.Redis.set", return_value=None) mocker.patch("redis.Redis.expire", return_value=None)