@@ -191,7 +191,7 @@ impl v2::HostConnection for crate::InstanceState {
191191 }
192192 } ) ;
193193
194- cmd. query_async :: < _ , RedisResults > ( conn)
194+ cmd. query_async :: < RedisResults > ( conn)
195195 . await
196196 . map ( |values| values. 0 )
197197 . map_err ( other_error)
@@ -296,18 +296,72 @@ struct RedisResults(Vec<RedisResult>);
296296
297297impl FromRedisValue for RedisResults {
298298 fn from_redis_value ( value : & Value ) -> redis:: RedisResult < Self > {
299- fn append ( values : & mut Vec < RedisResult > , value : & Value ) {
299+ fn append ( values : & mut Vec < RedisResult > , value : & Value ) -> redis :: RedisResult < ( ) > {
300300 match value {
301- Value :: Nil | Value :: Okay => ( ) ,
302- Value :: Int ( v) => values. push ( RedisResult :: Int64 ( * v) ) ,
303- Value :: Data ( bytes) => values. push ( RedisResult :: Binary ( bytes. to_owned ( ) ) ) ,
304- Value :: Bulk ( bulk) => bulk. iter ( ) . for_each ( |value| append ( values, value) ) ,
305- Value :: Status ( message) => values. push ( RedisResult :: Status ( message. to_owned ( ) ) ) ,
301+ Value :: Nil => {
302+ values. push ( RedisResult :: Nil ) ;
303+ Ok ( ( ) )
304+ }
305+ Value :: Int ( v) => {
306+ values. push ( RedisResult :: Int64 ( * v) ) ;
307+ Ok ( ( ) )
308+ }
309+ Value :: BulkString ( bytes) => {
310+ values. push ( RedisResult :: Binary ( bytes. to_owned ( ) ) ) ;
311+ Ok ( ( ) )
312+ }
313+ Value :: SimpleString ( s) => {
314+ values. push ( RedisResult :: Status ( s. to_owned ( ) ) ) ;
315+ Ok ( ( ) )
316+ }
317+ Value :: Okay => {
318+ values. push ( RedisResult :: Status ( "OK" . to_string ( ) ) ) ;
319+ Ok ( ( ) )
320+ }
321+ Value :: Map ( _) => Err ( redis:: RedisError :: from ( (
322+ redis:: ErrorKind :: TypeError ,
323+ "Could not convert Redis response" ,
324+ "Redis Map type is not supported" . to_string ( ) ,
325+ ) ) ) ,
326+ Value :: Attribute { .. } => Err ( redis:: RedisError :: from ( (
327+ redis:: ErrorKind :: TypeError ,
328+ "Could not convert Redis response" ,
329+ "Redis Attribute type is not supported" . to_string ( ) ,
330+ ) ) ) ,
331+ Value :: Array ( arr) | Value :: Set ( arr) => {
332+ arr. iter ( ) . try_for_each ( |value| append ( values, value) )
333+ }
334+ Value :: Double ( v) => {
335+ values. push ( RedisResult :: Binary ( v. to_string ( ) . into_bytes ( ) ) ) ;
336+ Ok ( ( ) )
337+ }
338+ Value :: VerbatimString { .. } => Err ( redis:: RedisError :: from ( (
339+ redis:: ErrorKind :: TypeError ,
340+ "Could not convert Redis response" ,
341+ "Redis string with format attribute is not supported" . to_string ( ) ,
342+ ) ) ) ,
343+ Value :: Boolean ( v) => {
344+ values. push ( RedisResult :: Int64 ( if * v { 1 } else { 0 } ) ) ;
345+ Ok ( ( ) )
346+ }
347+ Value :: BigNumber ( v) => {
348+ values. push ( RedisResult :: Binary ( v. to_string ( ) . as_bytes ( ) . to_owned ( ) ) ) ;
349+ Ok ( ( ) )
350+ }
351+ Value :: Push { .. } => Err ( redis:: RedisError :: from ( (
352+ redis:: ErrorKind :: TypeError ,
353+ "Could not convert Redis response" ,
354+ "Redis Pub/Sub types are not supported" . to_string ( ) ,
355+ ) ) ) ,
356+ Value :: ServerError ( err) => Err ( redis:: RedisError :: from ( (
357+ redis:: ErrorKind :: ResponseError ,
358+ "Server error" ,
359+ format ! ( "{err:?}" ) ,
360+ ) ) ) ,
306361 }
307362 }
308-
309363 let mut values = Vec :: new ( ) ;
310- append ( & mut values, value) ;
364+ append ( & mut values, value) ? ;
311365 Ok ( RedisResults ( values) )
312366 }
313367}
0 commit comments