fix: use Redis.from_url() for proper SSL support
Replace custom _parse_url() with redis.Redis.from_url() which properly handles rediss:// SSL connections and all URL parameters. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
6599b1b283
commit
685c2b576e
2 files changed
+7
-27
No files matched your search
+6
-26
@@ -319,14 +319,13 @@ class RedisStorage(BaseStorage):
|
||||
async def init_db(self) -> None:
|
||||
"""初始化Redis"""
|
||||
try:
|
||||
import redis.asyncio as redis
|
||||
parsed = self._parse_url(self.redis_url)
|
||||
logger.info(f"[Storage] Redis: {parsed['host']}:{parsed['port']}/{parsed['db']}")
|
||||
import redis.asyncio as aioredis
|
||||
parsed = urlparse(self.redis_url)
|
||||
db = int(parsed.path.lstrip('/')) if parsed.path and parsed.path != '/' else 0
|
||||
logger.info(f"[Storage] Redis: {parsed.hostname}:{parsed.port or 6379}/{db}")
|
||||
|
||||
self._redis = redis.Redis(
|
||||
host=parsed['host'], port=parsed['port'], password=parsed.get('password'),
|
||||
username=parsed.get('username'), db=parsed.get('db', 0),
|
||||
encoding="utf-8", decode_responses=True
|
||||
self._redis = aioredis.Redis.from_url(
|
||||
self.redis_url, encoding="utf-8", decode_responses=True
|
||||
)
|
||||
|
||||
await self._redis.ping()
|
||||
@@ -341,25 +340,6 @@ class RedisStorage(BaseStorage):
|
||||
logger.error(f"[Storage] Redis初始化失败: {e}")
|
||||
raise
|
||||
|
||||
def _parse_url(self, url: str) -> Dict[str, Any]:
|
||||
"""解析Redis URL"""
|
||||
if url.startswith('redis://'):
|
||||
url = url[8:]
|
||||
p = urlparse(f'//{url}')
|
||||
|
||||
result = {
|
||||
'host': p.hostname or 'localhost',
|
||||
'port': p.port or 6379,
|
||||
'db': int(p.path.lstrip('/')) if p.path and p.path != '/' else 0,
|
||||
'username': unquote(p.username) if p.username else None,
|
||||
'password': unquote(p.password) if p.password else None
|
||||
}
|
||||
|
||||
if result['password'] and not result['username']:
|
||||
result['username'] = 'default'
|
||||
|
||||
return result
|
||||
|
||||
async def _sync_data(self) -> None:
|
||||
"""同步数据"""
|
||||
try:
|
||||
|
||||
@@ -78,7 +78,7 @@ services:
|
||||
# - DATABASE_URL=mysql://user:password@host:3306/grok2api
|
||||
|
||||
## MySQL格式: mysql://user:password@host:port/database
|
||||
## Redis格式: redis://host:port/db 或 redis://user:password@host:port/db
|
||||
## Redis格式: redis://host:port/db 或 redis://user:password@host:port/db (SSL: rediss://)
|
||||
|
||||
volumes:
|
||||
grok_data:
|
||||
|
||||
Reference in new issue
Block a user