11use async_recursion:: async_recursion;
2- use redis:: Commands ;
2+ use redis:: { aio :: Connection , AsyncCommands } ;
33
44type Error = Box < dyn std:: error:: Error + Send + Sync + ' static > ;
55
66impl crate :: application:: CoLink {
7- fn _get_con_from_address ( & self , redis_address : & str ) -> Result < redis:: Connection , Error > {
8- let client = redis:: Client :: open ( redis_address) ?;
9- let con = client. get_connection ( ) ?;
10- Ok ( con)
11- }
12-
13- async fn _get_con_from_stored_credentials (
14- & self ,
15- key_path : & str ,
16- ) -> Result < redis:: Connection , Error > {
7+ async fn _get_con_from_stored_credentials ( & self , key_path : & str ) -> Result < Connection , Error > {
178 let redis_url_key = format ! ( "{}:redis_url" , key_path) ;
189 let redis_url = self . read_entry ( redis_url_key. as_str ( ) ) . await ?;
1910 let redis_url_string = String :: from_utf8 ( redis_url) ?;
20- self . _get_con_from_address ( redis_url_string. as_str ( ) )
11+ let client = redis:: Client :: open ( redis_url_string) ?;
12+ let con = client. get_async_connection ( ) . await ?;
13+ Ok ( con)
2114 }
2215
2316 #[ async_recursion]
@@ -28,7 +21,7 @@ impl crate::application::CoLink {
2821 payload : & [ u8 ] ,
2922 ) -> Result < String , Error > {
3023 let mut con = self . _get_con_from_stored_credentials ( address) . await ?;
31- let response: i32 = con. set_nx ( key_name, payload) ?;
24+ let response: i32 = con. set_nx ( key_name, payload) . await ?;
3225 if response == 0 {
3326 Err ( "key already exists." ) ?
3427 }
@@ -42,7 +35,7 @@ impl crate::application::CoLink {
4235 key_name : & str ,
4336 ) -> Result < Vec < u8 > , Error > {
4437 let mut con = self . _get_con_from_stored_credentials ( address) . await ?;
45- let response: Option < Vec < u8 > > = con. get ( key_name) ?;
38+ let response: Option < Vec < u8 > > = con. get ( key_name) . await ?;
4639 match response {
4740 Some ( response) => Ok ( response) ,
4841 None => Err ( "key does not exist." ) ?,
@@ -57,7 +50,7 @@ impl crate::application::CoLink {
5750 payload : & [ u8 ] ,
5851 ) -> Result < String , Error > {
5952 let mut con = self . _get_con_from_stored_credentials ( address) . await ?;
60- let response = con. set ( key_name, payload) ?;
53+ let response = con. set ( key_name, payload) . await ?;
6154 Ok ( response)
6255 }
6356
@@ -70,7 +63,8 @@ impl crate::application::CoLink {
7063 ) -> Result < String , Error > {
7164 let mut con = self . _get_con_from_stored_credentials ( address) . await ?;
7265 let response = con
73- . append :: < & str , & [ u8 ] , i32 > ( key_name, payload) ?
66+ . append :: < & str , & [ u8 ] , i32 > ( key_name, payload)
67+ . await ?
7468 . to_string ( ) ;
7569 Ok ( response)
7670 }
@@ -82,7 +76,7 @@ impl crate::application::CoLink {
8276 key_name : & str ,
8377 ) -> Result < String , Error > {
8478 let mut con = self . _get_con_from_stored_credentials ( address) . await ?;
85- let response: i32 = con. del ( key_name) ?;
79+ let response: i32 = con. del ( key_name) . await ?;
8680 if response == 0 {
8781 Err ( "key does not exist." ) ?
8882 }
0 commit comments