Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: double split error on redis port and some type hint (#11270)

yihong7b86f8f024d8
diff --git a/api/extensions/ext_redis.py b/api/extensions/ext_redis.py
index f97adc058cc..da418057079 100644
--- a/api/extensions/ext_redis.py
+++ b/api/extensions/ext_redis.py
@@ -1,3 +1,5 @@
+from typing import Any, Union
+
import redis
from redis.cluster import ClusterNode, RedisCluster
from redis.connection import Connection, SSLConnection
@@ -46,11 +48,11 @@ redis_client = RedisClientWrapper()
def init_app(app: DifyApp):
global redis_client
- connection_class = Connection
+ connection_class: type[Union[Connection, SSLConnection]] = Connection
if dify_config.REDIS_USE_SSL:
connection_class = SSLConnection
- redis_params = {
+ redis_params: dict[str, Any] = {
"username": dify_config.REDIS_USERNAME,
"password": dify_config.REDIS_PASSWORD,
"db": dify_config.REDIS_DB,
@@ -60,6 +62,7 @@ def init_app(app: DifyApp):
}
if dify_config.REDIS_USE_SENTINEL:
+ assert dify_config.REDIS_SENTINELS is not None, "REDIS_SENTINELS must be set when REDIS_USE_SENTINEL is True"
sentinel_hosts = [
(node.split(":")[0], int(node.split(":")[1])) for node in dify_config.REDIS_SENTINELS.split(",")
]
@@ -74,11 +77,13 @@ def init_app(app: DifyApp):
master = sentinel.master_for(dify_config.REDIS_SENTINEL_SERVICE_NAME, **redis_params)
redis_client.initialize(master)
elif dify_config.REDIS_USE_CLUSTERS:
+ assert dify_config.REDIS_CLUSTERS is not None, "REDIS_CLUSTERS must be set when REDIS_USE_CLUSTERS is True"
nodes = [
- ClusterNode(host=node.split(":")[0], port=int(node.split.split(":")[1]))
+ ClusterNode(host=node.split(":")[0], port=int(node.split(":")[1]))
for node in dify_config.REDIS_CLUSTERS.split(",")
]
- redis_client.initialize(RedisCluster(startup_nodes=nodes, password=dify_config.REDIS_CLUSTERS_PASSWORD))
+ # FIXME: mypy error here, try to figure out how to fix it
+ redis_client.initialize(RedisCluster(startup_nodes=nodes, password=dify_config.REDIS_CLUSTERS_PASSWORD)) # type: ignore
else:
redis_params.update(
{