Skip to content

Commit

Permalink
fix: double split error on redis port and some type hint (langgenius#…
Browse files Browse the repository at this point in the history
…11270)

Signed-off-by: yihong0618 <[email protected]>
  • Loading branch information
yihong0618 authored Dec 3, 2024
1 parent e686f12 commit 7b86f8f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions api/extensions/ext_redis.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any, Union

import redis
from redis.cluster import ClusterNode, RedisCluster
from redis.connection import Connection, SSLConnection
Expand Down Expand Up @@ -46,11 +48,11 @@ def __getattr__(self, item):

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,
Expand All @@ -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(",")
]
Expand All @@ -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(
{
Expand Down

0 comments on commit 7b86f8f

Please sign in to comment.