feat: 100% async - native async serializers (adata/asave/acreate), async cache (redis.asyncio), view call-site migration

This commit is contained in:
async-upgrade
2026-09-06 14:36:41 +08:00
parent 8f488fcaaa
commit 571641e539
18 changed files with 81 additions and 81 deletions
+3 -2
View File
@@ -1,6 +1,7 @@
import asyncio
import aiohttp
from utils.async_cache import aget_cache, aset_cache, adelete_cache
from asgiref.sync import sync_to_async
from rest_framework.permissions import AllowAny
@@ -106,7 +107,7 @@ class GetIPDataView(APIView):
cache_key = f"ip_location:{ip}"
# 先尝试从缓存获取(django-redis 为同步客户端,用 sync_to_async 兜底)
cached_data = await sync_to_async(default_cache.get)(cache_key)
cached_data = await aget_cache(cache_key)
if cached_data:
return Response(
{"code": 200, "message": "success", "data": cached_data},
@@ -143,7 +144,7 @@ class GetIPDataView(APIView):
}
# 写入缓存(sync_to_async 兜底)
await sync_to_async(default_cache.set)(cache_key, ip_info, IP_CACHE_TIMEOUT)
await aset_cache(cache_key, ip_info, IP_CACHE_TIMEOUT)
return Response(
{"code": 200, "message": "success", "data": ip_info},