1717from redis .asyncio import Redis as asyncRedis
1818from testcontainers .core .container import DockerContainer
1919from testcontainers .core .utils import raise_for_deprecated_parameter
20- from testcontainers .core .waiting_utils import wait_container_is_ready
20+ from testcontainers .core .wait_strategies import ExecWaitStrategy
2121
2222
2323class RedisContainer (DockerContainer ):
@@ -36,19 +36,14 @@ class RedisContainer(DockerContainer):
3636
3737 def __init__ (self , image : str = "redis:latest" , port : int = 6379 , password : Optional [str ] = None , ** kwargs ) -> None :
3838 raise_for_deprecated_parameter (kwargs , "port_to_expose" , "port" )
39- super ().__init__ (image , ** kwargs )
39+ wait_strategy = ExecWaitStrategy (["redis-cli" , "-a" , password , "ping" ] if password else ["redis-cli" , "ping" ])
40+ super ().__init__ (image , _wait_strategy = wait_strategy , ** kwargs )
4041 self .port = port
4142 self .password = password
4243 self .with_exposed_ports (self .port )
4344 if self .password :
4445 self .with_command (f"redis-server --requirepass { self .password } " )
4546
46- @wait_container_is_ready (redis .exceptions .ConnectionError )
47- def _connect (self ) -> None :
48- client = self .get_client ()
49- if not client .ping ():
50- raise redis .exceptions .ConnectionError ("Could not connect to Redis" )
51-
5247 def get_client (self , ** kwargs ) -> redis .Redis :
5348 """
5449 Get a redis client.
@@ -66,12 +61,6 @@ def get_client(self, **kwargs) -> redis.Redis:
6661 ** kwargs ,
6762 )
6863
69- def start (self ) -> "RedisContainer" :
70- super ().start ()
71- self ._connect ()
72- return self
73-
74-
7564class AsyncRedisContainer (RedisContainer ):
7665 """
7766 Redis container.
0 commit comments