@@ -515,12 +515,11 @@ RedisClient.prototype.connection_gone = function (why) {
515
515
} ;
516
516
517
517
RedisClient . prototype . return_error = function ( err ) {
518
- var command_obj = this . command_queue . shift ( ) , queue_len = this . command_queue . length ;
519
- // send_command might have been used wrong => catch those cases too
520
- if ( command_obj . command && command_obj . command . toUpperCase ) {
518
+ var command_obj = this . command_queue . shift ( ) ,
519
+ queue_len = this . command_queue . length ;
520
+
521
+ if ( command_obj && command_obj . command && command_obj . command . toUpperCase ) {
521
522
err . command = command_obj . command . toUpperCase ( ) ;
522
- } else {
523
- err . command = command_obj . command ;
524
523
}
525
524
526
525
var match = err . message . match ( utils . err_code ) ;
@@ -531,7 +530,7 @@ RedisClient.prototype.return_error = function (err) {
531
530
532
531
this . emit_idle ( queue_len ) ;
533
532
534
- if ( command_obj . callback ) {
533
+ if ( command_obj && command_obj . callback ) {
535
534
command_obj . callback ( err ) ;
536
535
} else {
537
536
this . emit ( 'error' , err ) ;
@@ -639,9 +638,9 @@ RedisClient.prototype.send_command = function (command, args, callback) {
639
638
big_data = false ,
640
639
prefix_keys ;
641
640
642
- if ( args === undefined ) {
641
+ if ( typeof args === ' undefined' ) {
643
642
args = [ ] ;
644
- } else if ( ! callback ) {
643
+ } else if ( typeof callback === 'undefined' ) {
645
644
if ( typeof args [ args . length - 1 ] === 'function' ) {
646
645
callback = args . pop ( ) ;
647
646
} else if ( typeof args [ args . length - 1 ] === 'undefined' ) {
@@ -689,12 +688,15 @@ RedisClient.prototype.send_command = function (command, args, callback) {
689
688
'Please handle this in your code to make sure everything works as you intended it to behave.' , command . toUpperCase ( )
690
689
) ;
691
690
args [ i ] = 'undefined' ; // Backwards compatible :/
691
+ } else {
692
+ args [ i ] = String ( args [ i ] ) ;
692
693
}
693
694
}
694
695
695
696
command_obj = new Command ( command , args , buffer_args , callback ) ;
696
697
697
- if ( ! this . ready && ! this . send_anyway || ! stream . writable ) {
698
+ // TODO: Replace send_anyway with `commands.hasFlag(command, 'loading') === false` as soon as pub_sub is handled in the result handler
699
+ if ( this . ready === false && this . send_anyway === false || ! stream . writable ) {
698
700
if ( this . closing || ! this . enable_offline_queue ) {
699
701
command = command . toUpperCase ( ) ;
700
702
if ( ! this . closing ) {
@@ -717,7 +719,7 @@ RedisClient.prototype.send_command = function (command, args, callback) {
717
719
}
718
720
719
721
if ( command === 'subscribe' || command === 'psubscribe' || command === 'unsubscribe' || command === 'punsubscribe' ) {
720
- this . pub_sub_command ( command_obj ) ;
722
+ this . pub_sub_command ( command_obj ) ; // TODO: This has to be moved to the result handler
721
723
} else if ( command === 'monitor' ) {
722
724
this . monitoring = true ;
723
725
} else if ( command === 'quit' ) {
@@ -740,7 +742,7 @@ RedisClient.prototype.send_command = function (command, args, callback) {
740
742
// This means that using Buffers in commands is going to be slower, so use Strings if you don't already have a Buffer.
741
743
command_str = '*' + ( args . length + 1 ) + '\r\n$' + command . length + '\r\n' + command + '\r\n' ;
742
744
743
- if ( ! buffer_args && ! big_data ) { // Build up a string and send entire command in one write
745
+ if ( buffer_args === false && big_data === false ) { // Build up a string and send entire command in one write
744
746
for ( i = 0 ; i < args . length ; i += 1 ) {
745
747
arg = args [ i ] ;
746
748
command_str += '$' + Buffer . byteLength ( arg ) + '\r\n' + arg + '\r\n' ;
@@ -890,7 +892,6 @@ commands.list.forEach(function (command) {
890
892
}
891
893
return this . send_command ( command , arr ) ;
892
894
} ;
893
-
894
895
Multi . prototype [ command . toUpperCase ( ) ] = Multi . prototype [ command ] = function ( key , arg , callback ) {
895
896
if ( Array . isArray ( key ) ) {
896
897
if ( arg ) {
@@ -1031,7 +1032,7 @@ RedisClient.prototype.hmset = RedisClient.prototype.HMSET = function (key, args,
1031
1032
return this . send_command ( 'hmset' , tmp_args , callback ) ;
1032
1033
}
1033
1034
var len = arguments . length ;
1034
- var tmp_args = new Array ( len ) ;
1035
+ tmp_args = new Array ( len ) ;
1035
1036
for ( var i = 0 ; i < len ; i += 1 ) {
1036
1037
tmp_args [ i ] = arguments [ i ] ;
1037
1038
}
@@ -1050,10 +1051,7 @@ Multi.prototype.hmset = Multi.prototype.HMSET = function (key, args, callback) {
1050
1051
args = args . concat ( [ callback ] ) ;
1051
1052
}
1052
1053
tmp_args = [ 'hmset' , key ] . concat ( args ) ;
1053
- } else if ( typeof args === 'object' ) {
1054
- if ( typeof key !== 'string' ) {
1055
- key = key . toString ( ) ;
1056
- }
1054
+ } else if ( typeof args === 'object' && ( typeof callback === 'function' || typeof callback === 'undefined' ) ) {
1057
1055
tmp_args = [ 'hmset' , key ] ;
1058
1056
var fields = Object . keys ( args ) ;
1059
1057
while ( field = fields . shift ( ) ) {
@@ -1065,7 +1063,7 @@ Multi.prototype.hmset = Multi.prototype.HMSET = function (key, args, callback) {
1065
1063
}
1066
1064
} else {
1067
1065
var len = arguments . length ;
1068
- var tmp_args = new Array ( len ) ;
1066
+ tmp_args = new Array ( len ) ;
1069
1067
tmp_args [ 0 ] = 'hmset' ;
1070
1068
for ( var i = 0 ; i < len ; i += 1 ) {
1071
1069
tmp_args [ i + 1 ] = arguments [ i ] ;
0 commit comments