55import  logging 
66from  typing  import  AsyncIterator , Dict , Union 
77
8- import  aioredis 
98import  pytest 
109import  tenacity 
10+ from  redis .asyncio  import  Redis , from_url 
1111from  settings_library .redis  import  RedisSettings 
1212from  tenacity .before_sleep  import  before_sleep_log 
1313from  tenacity .stop  import  stop_after_delay 
@@ -34,7 +34,7 @@ async def redis_settings(
3434    )
3535    # test runner is running on the host computer 
3636    settings  =  RedisSettings (REDIS_HOST = get_localhost_ip (), REDIS_PORT = int (port ))
37-     await  wait_till_redis_responsive (settings .dsn )
37+     await  wait_till_redis_responsive (settings .dsn_resources )
3838
3939    return  settings 
4040
@@ -56,15 +56,29 @@ def redis_service(
5656@pytest .fixture (scope = "function" ) 
5757async  def  redis_client (
5858    redis_settings : RedisSettings ,
59- ) ->  AsyncIterator [aioredis . Redis ]:
59+ ) ->  AsyncIterator [Redis ]:
6060    """Creates a redis client to communicate with a redis service ready""" 
61-     client  =  await  aioredis .create_redis_pool (redis_settings .dsn , encoding = "utf-8" )
61+     client  =  from_url (
62+         redis_settings .dsn_resources , encoding = "utf-8" , decode_responses = True 
63+     )
6264
6365    yield  client 
6466
6567    await  client .flushall ()
66-     client .close ()
67-     await  client .wait_closed ()
68+     await  client .close ()
69+ 
70+ 
71+ @pytest .fixture (scope = "function" ) 
72+ async  def  redis_locks_client (
73+     redis_settings : RedisSettings ,
74+ ) ->  AsyncIterator [Redis ]:
75+     """Creates a redis client to communicate with a redis service ready""" 
76+     client  =  from_url (redis_settings .dsn_locks , encoding = "utf-8" , decode_responses = True )
77+ 
78+     yield  client 
79+ 
80+     await  client .flushall ()
81+     await  client .close ()
6882
6983
7084# HELPERS -- 
@@ -77,6 +91,7 @@ async def redis_client(
7791    reraise = True , 
7892) 
7993async  def  wait_till_redis_responsive (redis_url : Union [URL , str ]) ->  None :
80-     client  =  await  aioredis .create_redis_pool (str (redis_url ), encoding = "utf-8" )
81-     client .close ()
82-     await  client .wait_closed ()
94+     client  =  from_url (f"{ redis_url }  " , encoding = "utf-8" , decode_responses = True )
95+ 
96+     if  not  await  client .ping ():
97+         raise  ConnectionError (f"{ redis_url = }   not available" )
0 commit comments