Files
2026-09-12 22:24:53 +08:00

40 lines
1.4 KiB
Python
Raw Permalink 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.
"""
Redis 缓存配置模块
=============================================================
包含 Redis 连接相关的所有配置项。
依赖:config/__init__.py 中的 _load_env_file() 已提前加载 .env
"""
import os
# ============================================================
# 缓存配置(Redis)
# ============================================================
# 缓存服务地址
REDIS_HOST = os.getenv('REDIS_HOST', '127.0.0.1')
# 缓存服务端口(Redis默认6379)
REDIS_PORT = int(os.getenv('REDIS_PORT', 6379))
# 缓存服务密码(务必使用强密码)
REDIS_PASSWORD = os.getenv('REDIS_PASSWORD', '')
# 缓存库索引(0-15,不同索引用于不同业务)
REDIS_INDEX = int(os.getenv('REDIS_INDEX', 0))
# 是否需要进行用户认证:True-开启,False-关闭(生产环境必须开启)
REDIS_AUTH = os.getenv('REDIS_AUTH', 'True') == 'True'
# 是否对查询结果进行编码处理:True-自动解码,False-返回字节数据
REDIS_DECODE_RESPONSES = os.getenv('REDIS_DECODE_RESPONSES', 'True') == 'True'
# Redis连接URL(方便直接使用)
# 仅在 AUTH 开启且密码非空时才拼入密码,避免密码泄露到日志
if REDIS_AUTH and REDIS_PASSWORD:
REDIS_URL = f'redis://:{REDIS_PASSWORD}@{REDIS_HOST}:{REDIS_PORT}/{REDIS_INDEX}'
else:
REDIS_URL = f'redis://{REDIS_HOST}:{REDIS_PORT}/{REDIS_INDEX}'