Files
JieXi/config.py
2025-11-28 21:20:40 +08:00

41 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import os
from dotenv import load_dotenv
load_dotenv()
class Config:
SECRET_KEY = os.getenv('SECRET_KEY', 'dev-secret-key-change-in-production')
# 数据库配置
SQLALCHEMY_DATABASE_URI = f"mysql+pymysql://{os.getenv('DB_USER', 'root')}:{os.getenv('DB_PASSWORD', '')}@{os.getenv('DB_HOST', 'localhost')}:{os.getenv('DB_PORT', '3306')}/{os.getenv('DB_NAME', 'video_parser')}?charset=utf8mb4"
SQLALCHEMY_TRACK_MODIFICATIONS = False
SQLALCHEMY_ECHO = False
# 数据库连接池配置(解决连接超时问题)
SQLALCHEMY_ENGINE_OPTIONS = {
'pool_size': 10, # 连接池大小
'pool_recycle': 3600, # 连接回收时间1小时防止 MySQL 8小时超时
'pool_pre_ping': True, # 每次从池中取连接前先 ping 一下,确保连接有效
'pool_timeout': 30, # 获取连接的超时时间
'max_overflow': 20, # 超过 pool_size 后最多创建的连接数
'connect_args': {
'connect_timeout': 10 # MySQL 连接超时时间
}
}
# Redis配置
REDIS_HOST = os.getenv('REDIS_HOST', 'localhost')
REDIS_PORT = int(os.getenv('REDIS_PORT', 6379))
REDIS_DB = int(os.getenv('REDIS_DB', 0))
REDIS_PASSWORD = os.getenv('REDIS_PASSWORD', None)
# 会话配置
PERMANENT_SESSION_LIFETIME = int(os.getenv('SESSION_LIFETIME', 7200))
# 并发配置
MAX_CONCURRENT = int(os.getenv('MAX_CONCURRENT', 3))
# 验证码配置
VERIFICATION_CODE_EXPIRE = 600 # 10分钟
VERIFICATION_CODE_LENGTH = 6