From 26c4ed6e2245ecd19423cadc0faf697241170528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8E=98=E6=9D=83=20=E9=A9=AC?= Date: Mon, 4 Sep 2023 14:38:35 +0800 Subject: [PATCH] feat: +code --- metagpt/memory/brain_memory.py | 8 ++++---- metagpt/utils/redis.py | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/metagpt/memory/brain_memory.py b/metagpt/memory/brain_memory.py index baad76562..3b27c2a94 100644 --- a/metagpt/memory/brain_memory.py +++ b/metagpt/memory/brain_memory.py @@ -93,8 +93,8 @@ class BrainMemory(pydantic.BaseModel): return hashlib.md5(text.encode()).hexdigest() @staticmethod - async def loads(redis_key: str) -> "BrainMemory": - redis = Redis() + async def loads(redis_key: str, redis_conf: Dict = None) -> "BrainMemory": + redis = Redis(conf=redis_conf) if not redis.is_valid() or not redis_key: return BrainMemory() v = await redis.get(key=redis_key) @@ -103,8 +103,8 @@ class BrainMemory(pydantic.BaseModel): return BrainMemory(**data) return BrainMemory() - async def dumps(self, redis_key: str, timeout_sec: int = 30 * 60): - redis = Redis() + async def dumps(self, redis_key: str, timeout_sec: int = 30 * 60, redis_conf: Dict = None): + redis = Redis(conf=redis_conf) if not redis.is_valid() or not redis_key: return False v = self.json() diff --git a/metagpt/utils/redis.py b/metagpt/utils/redis.py index ce9d1bc8e..7d1d88fbd 100644 --- a/metagpt/utils/redis.py +++ b/metagpt/utils/redis.py @@ -6,7 +6,7 @@ import json from datetime import timedelta from enum import Enum -from typing import Awaitable, Callable, Optional, Union +from typing import Awaitable, Callable, Dict, Optional, Union from redis import asyncio as aioredis @@ -184,8 +184,8 @@ class RedisManager: class Redis: - def __init__(self): - self._config = CONFIG.REDIS + def __init__(self, conf: Dict = None): + self._config = conf or CONFIG.REDIS if not self._config: return try: