@@ -337,33 +337,47 @@ fn math_rand(context: &Context, _this: &Value, _args: &[Value]) -> Result<Value>
337337}
338338
339339fn redis_exec ( context : & Context , _this : & Value , args : & [ Value ] ) -> Result < Value > {
340+ enum Parameter {
341+ Int64 ( i64 ) ,
342+ Binary ( ByteBuf ) ,
343+ }
344+
340345 println ! ( "execcuting exec" ) ;
341346 match args {
342347 [ address, command, arguments] => {
343348 let address = & deserialize_helper ( address) ?;
344349 let command = & deserialize_helper ( command) ?;
345- let mut arg: Vec < redis :: RedisParameter > = vec ! [ ] ;
350+ let mut arg = vec ! [ ] ;
346351 if arguments. is_array ( ) {
347352 let mut props = arguments. properties ( ) ?;
348353 while let Some ( ref _x) = props. next_key ( ) ? {
349354 let val = props. next_value ( ) ?;
350355 if val. is_big_int ( ) {
351356 let deserializer = & mut Deserializer :: from ( val. clone ( ) ) ;
352357 let temp = i64:: deserialize ( deserializer) ?;
353- arg. push ( redis :: RedisParameter :: Int64 ( temp) ) ;
358+ arg. push ( Parameter :: Int64 ( temp) ) ;
354359 } else if val. is_array_buffer ( ) {
355360 let deserializer = & mut Deserializer :: from ( val. clone ( ) ) ;
356361 let temp = ByteBuf :: deserialize ( deserializer) ?;
357- arg. push ( redis :: RedisParameter :: Binary ( & temp) ) ;
362+ arg. push ( Parameter :: Binary ( temp) ) ;
358363 } else {
359364 bail ! ( "invalid argument type, must be bigint or arraybuffer" )
360365 }
361366 }
362367 } else {
363368 bail ! ( "invalid argument type, must be array" )
364369 }
365- let results = redis:: execute ( address, command, & arg)
366- . map_err ( |_| anyhow ! ( "Error executing Redis execute command" ) ) ?;
370+ let results = redis:: execute (
371+ address,
372+ command,
373+ & arg. iter ( )
374+ . map ( |arg| match arg {
375+ Parameter :: Int64 ( v) => redis:: RedisParameter :: Int64 ( * v) ,
376+ Parameter :: Binary ( v) => redis:: RedisParameter :: Binary ( v. deref ( ) ) ,
377+ } )
378+ . collect :: < Vec < _ > > ( ) ,
379+ )
380+ . map_err ( |_| anyhow ! ( "Error executing Redis execute command" ) ) ?;
367381 let arr = context. array_value ( ) ?;
368382 for result in results. iter ( ) {
369383 match result {
0 commit comments