55import logging
66from contextlib import contextmanager
77from datetime import timedelta
8- from typing import Any , Literal , Protocol , TypeAlias , cast
8+ from typing import Any , Literal , Protocol , cast
99
1010import redis
1111from typing_extensions import deprecated
2626logger = logging .getLogger (__name__ )
2727
2828
29- @deprecated ("RedisPersistenceLayer will be removed in v4.0.0. Please use CacheProtocol instead." )
30- class RedisClientProtocol (Protocol ):
29+ class CacheClientProtocol (Protocol ):
3130 """
3231 Protocol class defining the interface for a Cache client.
3332
@@ -80,8 +79,7 @@ def delete(self, *names: bytes | str | memoryview) -> Any:
8079 raise NotImplementedError
8180
8281
83- @deprecated ("RedisConnection will be removed in v4.0.0. Please use CacheConnection instead." )
84- class RedisConnection :
82+ class CacheConnection :
8583 def __init__ (
8684 self ,
8785 url : str = "" ,
@@ -172,7 +170,7 @@ def create_subscription_payment(event: dict) -> Payment:
172170 self .ssl = ssl
173171 self .mode = mode
174172
175- def _init_client (self ) -> RedisClientProtocol :
173+ def _init_client (self ) -> CacheClientProtocol :
176174 logger .debug (f"Trying to connect to Redis: { self .host } " )
177175 client : type [redis .Redis | redis .cluster .RedisCluster ]
178176 if self .mode == "standalone" :
@@ -185,7 +183,7 @@ def _init_client(self) -> RedisClientProtocol:
185183 try :
186184 if self .url :
187185 logger .debug (f"Using URL format to connect to Cache: { self .host } " )
188- return cast (RedisClientProtocol , client .from_url (url = self .url ))
186+ return cast (CacheClientProtocol , client .from_url (url = self .url ))
189187 else :
190188 # Cache in cluster mode doesn't support db parameter
191189 extra_param_connection : dict [str , Any ] = {}
@@ -194,7 +192,7 @@ def _init_client(self) -> RedisClientProtocol:
194192
195193 logger .debug (f"Using arguments to connect to Cache: { self .host } " )
196194 return cast (
197- RedisClientProtocol ,
195+ CacheClientProtocol ,
198196 client (
199197 host = self .host ,
200198 port = self .port ,
@@ -210,8 +208,7 @@ def _init_client(self) -> RedisClientProtocol:
210208 raise IdempotencyPersistenceConnectionError ("Could not to connect to Cache endpoint" , exc ) from exc
211209
212210
213- @deprecated ("RedisCachePersistenceLayer will be removed in v4.0.0. Please use CachePersistenceLayer instead." )
214- class RedisCachePersistenceLayer (BasePersistenceLayer ):
211+ class CachePersistenceLayer (BasePersistenceLayer ):
215212 def __init__ (
216213 self ,
217214 url : str = "" ,
@@ -222,7 +219,7 @@ def __init__(
222219 db_index : int = 0 ,
223220 mode : Literal ["standalone" , "cluster" ] = "standalone" ,
224221 ssl : bool = True ,
225- client : RedisClientProtocol | None = None ,
222+ client : CacheClientProtocol | None = None ,
226223 in_progress_expiry_attr : str = "in_progress_expiration" ,
227224 expiry_attr : str = "expiration" ,
228225 status_attr : str = "status" ,
@@ -297,7 +294,7 @@ def lambda_handler(event: dict, context: LambdaContext):
297294
298295 # Initialize Cache client with cache config if no client is passed in
299296 if client is None :
300- self .client = RedisConnection (
297+ self .client = CacheConnection (
301298 host = host ,
302299 port = port ,
303300 username = username ,
@@ -517,6 +514,14 @@ def _delete_record(self, data_record: DataRecord) -> None:
517514 self .client .delete (data_record .idempotency_key )
518515
519516
520- CachePersistenceLayer : TypeAlias = RedisCachePersistenceLayer
521- CacheClientProtocol : TypeAlias = RedisClientProtocol
522- CacheConnection : TypeAlias = RedisConnection
517+ # Deprecated Redis* names are thin subclasses, so only they emit the DeprecationWarning.
518+ @deprecated ("RedisClientProtocol will be removed in v4.0.0. Please use CacheClientProtocol instead." )
519+ class RedisClientProtocol (CacheClientProtocol , Protocol ): ...
520+
521+
522+ @deprecated ("RedisConnection will be removed in v4.0.0. Please use CacheConnection instead." )
523+ class RedisConnection (CacheConnection ): ...
524+
525+
526+ @deprecated ("RedisCachePersistenceLayer will be removed in v4.0.0. Please use CachePersistenceLayer instead." )
527+ class RedisCachePersistenceLayer (CachePersistenceLayer ): ...
0 commit comments