circular-fix
Some checks failed
Deploy on push / deploy (push) Failing after 17s

This commit is contained in:
2025-08-17 16:33:54 +03:00
parent bc8447a444
commit e78e12eeee
65 changed files with 3304 additions and 1051 deletions

View File

@@ -1,6 +1,6 @@
import json
import logging
from typing import Any, Optional, Set, Union
from typing import Any, Set
import redis.asyncio as aioredis
@@ -20,7 +20,7 @@ class RedisService:
"""
def __init__(self, redis_url: str = REDIS_URL) -> None:
self._client: Optional[aioredis.Redis] = None
self._client: aioredis.Redis | None = None
self._redis_url = redis_url # Исправлено на _redis_url
self._is_available = aioredis is not None
@@ -126,11 +126,11 @@ class RedisService:
logger.exception("Redis command failed")
return None
async def get(self, key: str) -> Optional[Union[str, bytes]]:
async def get(self, key: str) -> str | bytes | None:
"""Get value by key"""
return await self.execute("get", key)
async def set(self, key: str, value: Any, ex: Optional[int] = None) -> bool:
async def set(self, key: str, value: Any, ex: int | None = None) -> bool:
"""Set key-value pair with optional expiration"""
if ex is not None:
result = await self.execute("setex", key, ex, value)
@@ -167,7 +167,7 @@ class RedisService:
"""Set hash field"""
await self.execute("hset", key, field, value)
async def hget(self, key: str, field: str) -> Optional[Union[str, bytes]]:
async def hget(self, key: str, field: str) -> str | bytes | None:
"""Get hash field"""
return await self.execute("hget", key, field)
@@ -213,10 +213,10 @@ class RedisService:
result = await self.execute("expire", key, seconds)
return bool(result)
async def serialize_and_set(self, key: str, data: Any, ex: Optional[int] = None) -> bool:
async def serialize_and_set(self, key: str, data: Any, ex: int | None = None) -> bool:
"""Serialize data to JSON and store in Redis"""
try:
if isinstance(data, (str, bytes)):
if isinstance(data, str | bytes):
serialized_data: bytes = data.encode("utf-8") if isinstance(data, str) else data
else:
serialized_data = json.dumps(data).encode("utf-8")