@@ -1106,15 +1106,24 @@ Multi.prototype.HMSET = Multi.prototype.hmset;
11061106Multi . prototype . exec = function ( callback ) {
11071107 var self = this ;
11081108 var errors = [ ] ;
1109+ var wants_buffers = [ ] ;
11091110 // drain queue, callback will catch "QUEUED" or error
11101111 // TODO - get rid of all of these anonymous functions which are elegant but slow
11111112 this . queue . forEach ( function ( args , index ) {
1112- var command = args [ 0 ] , obj ;
1113+ var command = args [ 0 ] , obj , i , il , buffer_args ;
11131114 if ( typeof args [ args . length - 1 ] === "function" ) {
11141115 args = args . slice ( 1 , - 1 ) ;
11151116 } else {
11161117 args = args . slice ( 1 ) ;
11171118 }
1119+ // Keep track of who wants buffer responses:
1120+ buffer_args = false ;
1121+ for ( i = 0 , il = args . length ; i < il ; i += 1 ) {
1122+ if ( Buffer . isBuffer ( args [ i ] ) ) {
1123+ buffer_args = true ;
1124+ }
1125+ }
1126+ wants_buffers . push ( buffer_args ) ;
11181127 if ( args . length === 1 && Array . isArray ( args [ 0 ] ) ) {
11191128 args = args [ 0 ] ;
11201129 }
@@ -1149,12 +1158,18 @@ Multi.prototype.exec = function (callback) {
11491158 }
11501159 }
11511160
1152- var i , il , reply , args ;
1161+ var i , il , reply , to_buffer , args ;
11531162
11541163 if ( replies ) {
11551164 for ( i = 1 , il = self . queue . length ; i < il ; i += 1 ) {
11561165 reply = replies [ i - 1 ] ;
11571166 args = self . queue [ i ] ;
1167+ to_buffer = wants_buffers [ i ] ;
1168+
1169+ // If we asked for strings, even in detect_buffers mode, then return strings:
1170+ if ( self . _client . options . detect_buffers && to_buffer === false ) {
1171+ replies [ i - 1 ] = reply = reply_to_strings ( reply ) ;
1172+ }
11581173
11591174 // TODO - confusing and error-prone that hgetall is special cased in two places
11601175 if ( reply && args [ 0 ] . toLowerCase ( ) === "hgetall" ) {
0 commit comments