@@ -1106,15 +1106,24 @@ Multi.prototype.HMSET = Multi.prototype.hmset;
1106
1106
Multi . prototype . exec = function ( callback ) {
1107
1107
var self = this ;
1108
1108
var errors = [ ] ;
1109
+ var wants_buffers = [ ] ;
1109
1110
// drain queue, callback will catch "QUEUED" or error
1110
1111
// TODO - get rid of all of these anonymous functions which are elegant but slow
1111
1112
this . queue . forEach ( function ( args , index ) {
1112
- var command = args [ 0 ] , obj ;
1113
+ var command = args [ 0 ] , obj , i , il , buffer_args ;
1113
1114
if ( typeof args [ args . length - 1 ] === "function" ) {
1114
1115
args = args . slice ( 1 , - 1 ) ;
1115
1116
} else {
1116
1117
args = args . slice ( 1 ) ;
1117
1118
}
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 ) ;
1118
1127
if ( args . length === 1 && Array . isArray ( args [ 0 ] ) ) {
1119
1128
args = args [ 0 ] ;
1120
1129
}
@@ -1149,12 +1158,18 @@ Multi.prototype.exec = function (callback) {
1149
1158
}
1150
1159
}
1151
1160
1152
- var i , il , reply , args ;
1161
+ var i , il , reply , to_buffer , args ;
1153
1162
1154
1163
if ( replies ) {
1155
1164
for ( i = 1 , il = self . queue . length ; i < il ; i += 1 ) {
1156
1165
reply = replies [ i - 1 ] ;
1157
1166
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
+ }
1158
1173
1159
1174
// TODO - confusing and error-prone that hgetall is special cased in two places
1160
1175
if ( reply && args [ 0 ] . toLowerCase ( ) === "hgetall" ) {
0 commit comments