fix(cache): type async Redis loop registries

This commit is contained in:
jxxghp
2026-09-19 18:36:16 +08:00
parent ecbdcd5726
commit f14eddfa03
2 changed files with 10 additions and 6 deletions

View File

@@ -382,8 +382,12 @@ class AsyncRedisHelper(ConfigReloadMixin, metaclass=Singleton):
self.redis_url = get_runtime_setting('CACHE_BACKEND_URL')
self.client: Optional[Redis] = None
self._loop: Optional[asyncio.AbstractEventLoop] = None
self._clients: weakref.WeakKeyDictionary = weakref.WeakKeyDictionary()
self._connect_locks: weakref.WeakKeyDictionary = weakref.WeakKeyDictionary()
self._clients: weakref.WeakKeyDictionary[
asyncio.AbstractEventLoop, Redis
] = weakref.WeakKeyDictionary()
self._connect_locks: weakref.WeakKeyDictionary[
asyncio.AbstractEventLoop, asyncio.Lock
] = weakref.WeakKeyDictionary()
self._state_lock = threading.RLock()
def _get_connect_lock(self, current_loop: asyncio.AbstractEventLoop) -> asyncio.Lock:
@@ -422,7 +426,7 @@ class AsyncRedisHelper(ConfigReloadMixin, metaclass=Singleton):
"""
current_loop = asyncio.get_running_loop()
connect_lock = self._get_connect_lock(current_loop)
client = None
client: Optional[Redis] = None
try:
async with connect_lock:
with self._state_lock:

View File

@@ -10,11 +10,11 @@
"app/adapters/cache/redis.py": {
"arg-type": 9,
"no-any-return": 2,
"no-untyped-call": 21,
"no-untyped-def": 16,
"no-untyped-call": 12,
"no-untyped-def": 15,
"return-value": 2,
"str-bytes-safe": 2,
"union-attr": 27
"union-attr": 14
},
"app/adapters/external/cookiecloud.py": {
"arg-type": 1