diff --git a/backend/api/core/Redis.py b/backend/api/core/Redis.py index 303cb5ef..61d87724 100644 --- a/backend/api/core/Redis.py +++ b/backend/api/core/Redis.py @@ -1,9 +1,10 @@ +import inspect import json from api.core.Gzip import gzip_zip, gzip_unzip from config.main import config -def get_redis_info(redis, key, fun, expire = 0, without_gzip=False): +async def get_redis_info(redis, key, fun, expire = 0, without_gzip=False): info = None if not config.DEBUG_MODE and redis: try: @@ -14,7 +15,10 @@ def get_redis_info(redis, key, fun, expire = 0, without_gzip=False): except Exception: info = None if info is None: - info = fun() + if inspect.iscoroutinefunction(fun): + info = await fun() + else: + info = fun() if not config.DEBUG_MODE and redis and info is not None: if without_gzip: redis.set(key, json.dumps(info)) diff --git a/backend/api/routes/colg.py b/backend/api/routes/colg.py index 1badc9e0..05b11651 100644 --- a/backend/api/routes/colg.py +++ b/backend/api/routes/colg.py @@ -182,6 +182,7 @@ async def get_official_gold(redis: RedisDep) -> Response[list[OfficialGold]]: } ) return datas + except Exception as e: print(e) return response(data=[])