@@ -948,20 +948,17 @@ commands.list.forEach(function (command) {
948
948
RedisClient . prototype [ command . toUpperCase ( ) ] = RedisClient . prototype [ command ] = function ( key , arg , callback ) {
949
949
if ( Array . isArray ( key ) ) {
950
950
return this . send_command ( command , key , arg ) ;
951
- }
952
- if ( Array . isArray ( arg ) ) {
951
+ } else if ( Array . isArray ( arg ) ) {
953
952
arg = [ key ] . concat ( arg ) ;
954
953
return this . send_command ( command , arg , callback ) ;
955
954
}
956
- // Speed up the common case
955
+ // This has to be inlined, otherwise the arguments leak
957
956
var len = arguments . length ;
958
- if ( len === 2 ) {
959
- return this . send_command ( command , [ key , arg ] ) ;
960
- }
961
- if ( len === 3 ) {
962
- return this . send_command ( command , [ key , arg , callback ] ) ;
957
+ var arr = new Array ( len ) ;
958
+ for ( var i = 0 ; i < len ; i += 1 ) {
959
+ arr [ i ] = arguments [ i ] ;
963
960
}
964
- return this . send_command ( command , utils . to_array ( arguments ) ) ;
961
+ return this . send_command ( command , arr ) ;
965
962
} ;
966
963
967
964
Multi . prototype [ command . toUpperCase ( ) ] = Multi . prototype [ command ] = function ( key , arg , callback ) {
@@ -976,15 +973,12 @@ commands.list.forEach(function (command) {
976
973
}
977
974
this . queue . push ( [ command , key ] . concat ( arg ) ) ;
978
975
} else {
979
- // Speed up the common case
980
976
var len = arguments . length ;
981
- if ( len === 2 ) {
982
- this . queue . push ( [ command , key , arg ] ) ;
983
- } else if ( len === 3 ) {
984
- this . queue . push ( [ command , key , arg , callback ] ) ;
985
- } else {
986
- this . queue . push ( [ command ] . concat ( utils . to_array ( arguments ) ) ) ;
977
+ var arr = new Array ( len ) ;
978
+ for ( var i = 0 ; i < len ; i += 1 ) {
979
+ arr [ i ] = arguments [ i ] ;
987
980
}
981
+ this . queue . push ( [ command ] . concat ( arr ) ) ;
988
982
}
989
983
return this ;
990
984
} ;
@@ -1051,23 +1045,22 @@ RedisClient.prototype.hmset = RedisClient.prototype.HMSET = function (key, args,
1051
1045
if ( Array . isArray ( args ) ) {
1052
1046
return this . send_command ( 'hmset' , [ key ] . concat ( args ) , callback ) ;
1053
1047
}
1054
- if ( typeof args === 'object' ) {
1048
+ if ( typeof args === 'object' && ( typeof callback === 'function' || typeof callback === 'undefined' ) ) {
1055
1049
// User does: client.hmset(key, {key1: val1, key2: val2})
1056
1050
// assuming key is a string, i.e. email address
1057
-
1058
- // if key is a number, i.e. timestamp, convert to string
1059
- // TODO: This seems random and no other command get's the key converted => either all or none should behave like this
1060
- if ( typeof key !== 'string' ) {
1061
- key = key . toString ( ) ;
1062
- }
1063
1051
tmp_args = [ key ] ;
1064
1052
var fields = Object . keys ( args ) ;
1065
1053
while ( field = fields . shift ( ) ) {
1066
1054
tmp_args . push ( field , args [ field ] ) ;
1067
1055
}
1068
1056
return this . send_command ( 'hmset' , tmp_args , callback ) ;
1069
1057
}
1070
- return this . send_command ( 'hmset' , utils . to_array ( arguments ) ) ;
1058
+ var len = arguments . length ;
1059
+ var tmp_args = new Array ( len ) ;
1060
+ for ( var i = 0 ; i < len ; i += 1 ) {
1061
+ tmp_args [ i ] = arguments [ i ] ;
1062
+ }
1063
+ return this . send_command ( 'hmset' , tmp_args ) ;
1071
1064
} ;
1072
1065
1073
1066
Multi . prototype . hmset = Multi . prototype . HMSET = function ( key , args , callback ) {
@@ -1096,8 +1089,12 @@ Multi.prototype.hmset = Multi.prototype.HMSET = function (key, args, callback) {
1096
1089
tmp_args . push ( callback ) ;
1097
1090
}
1098
1091
} else {
1099
- tmp_args = utils . to_array ( arguments ) ;
1100
- tmp_args . unshift ( 'hmset' ) ;
1092
+ var len = arguments . length ;
1093
+ var tmp_args = new Array ( len ) ;
1094
+ tmp_args [ 0 ] = 'hmset' ;
1095
+ for ( var i = 0 ; i < len ; i += 1 ) {
1096
+ tmp_args [ i + 1 ] = arguments [ i ] ;
1097
+ }
1101
1098
}
1102
1099
this . queue . push ( tmp_args ) ;
1103
1100
return this ;
@@ -1231,7 +1228,7 @@ Multi.prototype.exec = Multi.prototype.EXEC = Multi.prototype.exec_batch = funct
1231
1228
var index = 0 ;
1232
1229
var args ;
1233
1230
var args_len = 1 ;
1234
- var callbackWithoutCB = function ( err , res ) {
1231
+ var callback_without_own_cb = function ( err , res ) {
1235
1232
if ( err ) {
1236
1233
self . results . push ( err ) ;
1237
1234
// Add the position to the error
@@ -1243,7 +1240,7 @@ Multi.prototype.exec = Multi.prototype.EXEC = Multi.prototype.exec_batch = funct
1243
1240
// Do not emit an error here. Otherwise each error would result in one emit.
1244
1241
// The errors will be returned in the result anyway
1245
1242
} ;
1246
- var lastCallback = function ( cb ) {
1243
+ var last_callback = function ( cb ) {
1247
1244
return function ( err , res ) {
1248
1245
cb ( err , res ) ;
1249
1246
callback ( null , self . results ) ;
@@ -1263,19 +1260,17 @@ Multi.prototype.exec = Multi.prototype.EXEC = Multi.prototype.exec_batch = funct
1263
1260
while ( args = this . queue . shift ( ) ) {
1264
1261
var command = args . shift ( ) ;
1265
1262
var cb ;
1266
- // Improve the callback function generation by using new Function
1267
- // check https://github.com/petkaantonov/bluebird/blob/master/src/promisify.js
1268
1263
args_len = args . length - 1 ;
1269
1264
if ( typeof args [ args_len ] === 'function' ) {
1270
1265
cb = this . callback ( args . pop ( ) , index ) ;
1271
1266
} else {
1272
- cb = callbackWithoutCB ;
1267
+ cb = callback_without_own_cb ;
1273
1268
if ( typeof args [ args_len ] === 'undefined' ) {
1274
1269
args . pop ( ) ;
1275
1270
}
1276
1271
}
1277
1272
if ( callback && index === len - 1 ) {
1278
- cb = lastCallback ( cb ) ;
1273
+ cb = last_callback ( cb ) ;
1279
1274
}
1280
1275
this . _client . send_command ( command , args , cb ) ;
1281
1276
index ++ ;
0 commit comments