From 82da8dde1ed58d68abe3ac60d104899fed89a4c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D0=B4=D0=B8=D0=BC=20=D0=A5=D1=80=D0=B8=D1=81?= =?UTF-8?q?=D1=82=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Mon, 7 Apr 2025 17:18:43 +0000 Subject: [PATCH] feat(storage): add get_value method to RedisStorage --- aiogram/fsm/storage/redis.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/aiogram/fsm/storage/redis.py b/aiogram/fsm/storage/redis.py index edcf9d63..d686ae63 100644 --- a/aiogram/fsm/storage/redis.py +++ b/aiogram/fsm/storage/redis.py @@ -1,6 +1,6 @@ import json from contextlib import asynccontextmanager -from typing import Any, AsyncGenerator, Callable, Dict, Optional, cast +from typing import Any, AsyncGenerator, Callable, Dict, Optional, cast, overload from redis.asyncio.client import Redis from redis.asyncio.connection import ConnectionPool @@ -127,6 +127,18 @@ class RedisStorage(BaseStorage): value = value.decode("utf-8") return cast(Dict[str, Any], self.json_loads(value)) + @overload + async def get_value(self, storage_key: StorageKey, dict_key: str) -> Optional[Any]: ... + + @overload + async def get_value(self, storage_key: StorageKey, dict_key: str, default: Any) -> Any: ... + + async def get_value( + self, storage_key: StorageKey, dict_key: str, default: Optional[Any] = None + ) -> Optional[Any]: + data = await self.get_data(storage_key) + return data.get(dict_key, default) + class RedisEventIsolation(BaseEventIsolation): def __init__(