ss
This commit is contained in:
69
backend/app/core/redis_client.py
Normal file
69
backend/app/core/redis_client.py
Normal file
@@ -0,0 +1,69 @@
|
||||
"""
|
||||
Redis客户端
|
||||
"""
|
||||
import redis
|
||||
from app.core.config import settings
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_redis_client = None
|
||||
|
||||
def get_redis_client():
|
||||
"""
|
||||
获取Redis客户端(单例模式)
|
||||
|
||||
Returns:
|
||||
redis.Redis: Redis客户端实例,如果连接失败则返回None
|
||||
"""
|
||||
global _redis_client
|
||||
|
||||
if _redis_client is not None:
|
||||
try:
|
||||
# 测试连接
|
||||
_redis_client.ping()
|
||||
return _redis_client
|
||||
except:
|
||||
# 连接已断开,重新创建
|
||||
_redis_client = None
|
||||
|
||||
try:
|
||||
redis_url = getattr(settings, 'REDIS_URL', None)
|
||||
if not redis_url:
|
||||
logger.warning("REDIS_URL未配置,无法使用Redis缓存")
|
||||
return None
|
||||
|
||||
# 解析Redis URL: redis://host:port/db
|
||||
if redis_url.startswith('redis://'):
|
||||
redis_url = redis_url.replace('redis://', '')
|
||||
|
||||
# 分离host:port和db
|
||||
parts = redis_url.split('/')
|
||||
host_port = parts[0]
|
||||
db = int(parts[1]) if len(parts) > 1 and parts[1].isdigit() else 0
|
||||
|
||||
# 分离host和port
|
||||
if ':' in host_port:
|
||||
host, port = host_port.split(':')
|
||||
port = int(port)
|
||||
else:
|
||||
host = host_port
|
||||
port = 6379
|
||||
|
||||
_redis_client = redis.Redis(
|
||||
host=host,
|
||||
port=port,
|
||||
db=db,
|
||||
decode_responses=True, # 自动解码为字符串
|
||||
socket_connect_timeout=2,
|
||||
socket_timeout=2
|
||||
)
|
||||
|
||||
# 测试连接
|
||||
_redis_client.ping()
|
||||
logger.info(f"Redis连接成功: {host}:{port}/{db}")
|
||||
return _redis_client
|
||||
except Exception as e:
|
||||
logger.warning(f"Redis连接失败: {str(e)},将使用内存缓存")
|
||||
_redis_client = None
|
||||
return None
|
||||
File diff suppressed because it is too large
Load Diff
@@ -71,7 +71,7 @@ class WorkflowValidator:
|
||||
node_type = node.get('type')
|
||||
if not node_type:
|
||||
self.errors.append(f"节点 {node_id} 缺少类型")
|
||||
elif node_type not in ['start', 'input', 'llm', 'condition', 'transform', 'output', 'end', 'default', 'loop', 'foreach', 'loop_end', 'agent', 'http', 'request', 'database', 'db', 'file', 'file_operation', 'schedule', 'delay', 'timer', 'webhook', 'email', 'mail', 'message_queue', 'mq', 'rabbitmq', 'kafka']:
|
||||
elif node_type not in ['start', 'input', 'llm', 'condition', 'transform', 'output', 'end', 'default', 'loop', 'foreach', 'loop_end', 'agent', 'http', 'request', 'database', 'db', 'file', 'file_operation', 'schedule', 'delay', 'timer', 'webhook', 'email', 'mail', 'message_queue', 'mq', 'rabbitmq', 'kafka', 'switch', 'merge', 'wait', 'json', 'text', 'cache', 'vector_db', 'log', 'error_handler', 'csv', 'object_storage', 'slack', 'dingtalk', 'dingding', 'wechat_work', 'wecom', 'sms', 'pdf', 'image', 'excel', 'subworkflow', 'code', 'oauth', 'validator', 'batch']:
|
||||
self.warnings.append(f"节点 {node_id} 使用了未知类型: {node_type}")
|
||||
|
||||
def _validate_edges(self):
|
||||
|
||||
Reference in New Issue
Block a user