mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-12 20:59:00 +08:00
fix: double split error on redis port and some type hint (#11270)
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
This commit is contained in:
parent
e686f12317
commit
7b86f8f024
@ -1,3 +1,5 @@
|
|||||||
|
from typing import Any, Union
|
||||||
|
|
||||||
import redis
|
import redis
|
||||||
from redis.cluster import ClusterNode, RedisCluster
|
from redis.cluster import ClusterNode, RedisCluster
|
||||||
from redis.connection import Connection, SSLConnection
|
from redis.connection import Connection, SSLConnection
|
||||||
@ -46,11 +48,11 @@ redis_client = RedisClientWrapper()
|
|||||||
|
|
||||||
def init_app(app: DifyApp):
|
def init_app(app: DifyApp):
|
||||||
global redis_client
|
global redis_client
|
||||||
connection_class = Connection
|
connection_class: type[Union[Connection, SSLConnection]] = Connection
|
||||||
if dify_config.REDIS_USE_SSL:
|
if dify_config.REDIS_USE_SSL:
|
||||||
connection_class = SSLConnection
|
connection_class = SSLConnection
|
||||||
|
|
||||||
redis_params = {
|
redis_params: dict[str, Any] = {
|
||||||
"username": dify_config.REDIS_USERNAME,
|
"username": dify_config.REDIS_USERNAME,
|
||||||
"password": dify_config.REDIS_PASSWORD,
|
"password": dify_config.REDIS_PASSWORD,
|
||||||
"db": dify_config.REDIS_DB,
|
"db": dify_config.REDIS_DB,
|
||||||
@ -60,6 +62,7 @@ def init_app(app: DifyApp):
|
|||||||
}
|
}
|
||||||
|
|
||||||
if dify_config.REDIS_USE_SENTINEL:
|
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 = [
|
sentinel_hosts = [
|
||||||
(node.split(":")[0], int(node.split(":")[1])) for node in dify_config.REDIS_SENTINELS.split(",")
|
(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)
|
master = sentinel.master_for(dify_config.REDIS_SENTINEL_SERVICE_NAME, **redis_params)
|
||||||
redis_client.initialize(master)
|
redis_client.initialize(master)
|
||||||
elif dify_config.REDIS_USE_CLUSTERS:
|
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 = [
|
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(",")
|
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:
|
else:
|
||||||
redis_params.update(
|
redis_params.update(
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user