This commit is contained in:
2026-03-09 18:53:18 +08:00
parent 621023bf34
commit b1a87fdb46
2 changed files with 7 additions and 2 deletions
+6 -2
View File
@@ -1,9 +1,10 @@
import inspect
import json import json
from api.core.Gzip import gzip_zip, gzip_unzip from api.core.Gzip import gzip_zip, gzip_unzip
from config.main import config 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 info = None
if not config.DEBUG_MODE and redis: if not config.DEBUG_MODE and redis:
try: try:
@@ -14,7 +15,10 @@ def get_redis_info(redis, key, fun, expire = 0, without_gzip=False):
except Exception: except Exception:
info = None info = None
if info is 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 not config.DEBUG_MODE and redis and info is not None:
if without_gzip: if without_gzip:
redis.set(key, json.dumps(info)) redis.set(key, json.dumps(info))
+1
View File
@@ -182,6 +182,7 @@ async def get_official_gold(redis: RedisDep) -> Response[list[OfficialGold]]:
} }
) )
return datas return datas
except Exception as e: except Exception as e:
print(e) print(e)
return response(data=[]) return response(data=[])