@@ -40,27 +40,35 @@ impl std::error::Error for Error {
4040 }
4141}
4242
43+ impl From < RedisError > for Error {
44+ fn from ( value : RedisError ) -> Self {
45+ Error :: Redis ( value)
46+ }
47+ }
48+
49+ pub type Result < T > = core:: result:: Result < T , Error > ;
50+
4351impl DbPool {
44- pub async fn new ( timeout : Duration , db_host : String ) -> RedisResult < Self > {
52+ pub async fn new ( timeout : Duration , db_host : String ) -> Result < Self > {
4553 let client = Client :: open ( format ! ( "redis://{}" , db_host) ) ?;
4654 Ok ( Self { client, timeout } )
4755 }
4856
4957 /// Peek using [`DEFAULT_COLUMN`] as the channel type.
50- pub async fn push_default ( & self , subdirectory_id : & str , data : Vec < u8 > ) -> RedisResult < ( ) > {
58+ pub async fn push_default ( & self , subdirectory_id : & str , data : Vec < u8 > ) -> Result < ( ) > {
5159 self . push ( subdirectory_id, DEFAULT_COLUMN , data) . await
5260 }
5361
54- pub async fn peek_default ( & self , subdirectory_id : & str ) -> Result < Vec < u8 > , Error > {
62+ pub async fn peek_default ( & self , subdirectory_id : & str ) -> Result < Vec < u8 > > {
5563 self . peek_with_timeout ( subdirectory_id, DEFAULT_COLUMN ) . await
5664 }
5765
58- pub async fn push_v1 ( & self , subdirectory_id : & str , data : Vec < u8 > ) -> RedisResult < ( ) > {
66+ pub async fn push_v1 ( & self , subdirectory_id : & str , data : Vec < u8 > ) -> Result < ( ) > {
5967 self . push ( subdirectory_id, PJ_V1_COLUMN , data) . await
6068 }
6169
6270 /// Peek using [`PJ_V1_COLUMN`] as the channel type.
63- pub async fn peek_v1 ( & self , subdirectory_id : & str ) -> Result < Vec < u8 > , Error > {
71+ pub async fn peek_v1 ( & self , subdirectory_id : & str ) -> Result < Vec < u8 > > {
6472 self . peek_with_timeout ( subdirectory_id, PJ_V1_COLUMN ) . await
6573 }
6674
@@ -69,7 +77,7 @@ impl DbPool {
6977 subdirectory_id : & str ,
7078 channel_type : & str ,
7179 data : Vec < u8 > ,
72- ) -> RedisResult < ( ) > {
80+ ) -> Result < ( ) > {
7381 let mut conn = self . client . get_async_connection ( ) . await ?;
7482 let key = channel_name ( subdirectory_id, channel_type) ;
7583 ( ) = conn. set ( & key, data. clone ( ) ) . await ?;
@@ -81,7 +89,7 @@ impl DbPool {
8189 & self ,
8290 subdirectory_id : & str ,
8391 channel_type : & str ,
84- ) -> Result < Vec < u8 > , Error > {
92+ ) -> Result < Vec < u8 > > {
8593 match tokio:: time:: timeout ( self . timeout , self . peek ( subdirectory_id, channel_type) ) . await {
8694 Ok ( redis_result) => match redis_result {
8795 Ok ( result) => Ok ( result) ,
0 commit comments