@@ -556,9 +556,8 @@ function reply_to_strings(reply) {
556
556
557
557
if ( Array . isArray ( reply ) ) {
558
558
for ( i = 0 ; i < reply . length ; i ++ ) {
559
- if ( reply [ i ] !== null && reply [ i ] !== undefined ) {
560
- reply [ i ] = reply [ i ] . toString ( ) ;
561
- }
559
+ // Recusivly call the function as slowlog returns deep nested replies
560
+ reply [ i ] = reply_to_strings ( reply [ i ] ) ;
562
561
}
563
562
return reply ;
564
563
}
@@ -612,14 +611,17 @@ RedisClient.prototype.return_reply = function (reply) {
612
611
} else {
613
612
debug ( "No callback for reply" ) ;
614
613
}
615
- } else if ( this . pub_sub_mode || ( command_obj && command_obj . sub_command ) ) {
614
+ } else if ( this . pub_sub_mode || command_obj && command_obj . sub_command ) {
616
615
if ( Array . isArray ( reply ) ) {
616
+ if ( ! this . options . return_buffers && ( ! command_obj || this . options . detect_buffers && command_obj . buffer_args === false ) ) {
617
+ reply = reply_to_strings ( reply ) ;
618
+ }
617
619
type = reply [ 0 ] . toString ( ) ;
618
620
619
621
if ( type === "message" ) {
620
- this . emit ( "message" , reply [ 1 ] . toString ( ) , reply [ 2 ] ) ; // channel, message
622
+ this . emit ( "message" , reply [ 1 ] , reply [ 2 ] ) ; // channel, message
621
623
} else if ( type === "pmessage" ) {
622
- this . emit ( "pmessage" , reply [ 1 ] . toString ( ) , reply [ 2 ] . toString ( ) , reply [ 3 ] ) ; // pattern, channel, message
624
+ this . emit ( "pmessage" , reply [ 1 ] , reply [ 2 ] , reply [ 3 ] ) ; // pattern, channel, message
623
625
} else if ( type === "subscribe" || type === "unsubscribe" || type === "psubscribe" || type === "punsubscribe" ) {
624
626
if ( reply [ 2 ] === 0 ) {
625
627
this . pub_sub_mode = false ;
@@ -629,12 +631,10 @@ RedisClient.prototype.return_reply = function (reply) {
629
631
}
630
632
// subscribe commands take an optional callback and also emit an event, but only the first response is included in the callback
631
633
// TODO - document this or fix it so it works in a more obvious way
632
- // reply[1] can be null
633
- var reply1String = ( reply [ 1 ] === null ) ? null : reply [ 1 ] . toString ( ) ;
634
634
if ( command_obj && typeof command_obj . callback === "function" ) {
635
- command_obj . callback ( null , reply1String ) ;
635
+ command_obj . callback ( null , reply [ 1 ] ) ;
636
636
}
637
- this . emit ( type , reply1String , reply [ 2 ] ) ; // channel, count
637
+ this . emit ( type , reply [ 1 ] , reply [ 2 ] ) ; // channel, count
638
638
} else {
639
639
this . emit ( "error" , new Error ( "subscriptions are active but got unknown reply type " + type ) ) ;
640
640
return ;
@@ -644,6 +644,9 @@ RedisClient.prototype.return_reply = function (reply) {
644
644
return ;
645
645
}
646
646
} else if ( this . monitoring ) {
647
+ if ( Buffer . isBuffer ( reply ) ) {
648
+ reply = reply . toString ( ) ;
649
+ }
647
650
len = reply . indexOf ( " " ) ;
648
651
timestamp = reply . slice ( 0 , len ) ;
649
652
argindex = reply . indexOf ( '"' ) ;
@@ -776,7 +779,7 @@ RedisClient.prototype.send_command = function (command, args, callback) {
776
779
777
780
for ( i = 0 ; i < args . length ; i += 1 ) {
778
781
arg = args [ i ] ;
779
- if ( ! ( Buffer . isBuffer ( arg ) || arg instanceof String ) ) {
782
+ if ( ! ( Buffer . isBuffer ( arg ) || typeof arg === 'string' ) ) {
780
783
arg = String ( arg ) ;
781
784
}
782
785
0 commit comments