@@ -515,12 +515,11 @@ RedisClient.prototype.connection_gone = function (why) {
515515} ;
516516
517517RedisClient . 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 ) {
521522 err . command = command_obj . command . toUpperCase ( ) ;
522- } else {
523- err . command = command_obj . command ;
524523 }
525524
526525 var match = err . message . match ( utils . err_code ) ;
@@ -531,7 +530,7 @@ RedisClient.prototype.return_error = function (err) {
531530
532531 this . emit_idle ( queue_len ) ;
533532
534- if ( command_obj . callback ) {
533+ if ( command_obj && command_obj . callback ) {
535534 command_obj . callback ( err ) ;
536535 } else {
537536 this . emit ( 'error' , err ) ;
@@ -639,9 +638,9 @@ RedisClient.prototype.send_command = function (command, args, callback) {
639638 big_data = false ,
640639 prefix_keys ;
641640
642- if ( args === undefined ) {
641+ if ( typeof args === ' undefined' ) {
643642 args = [ ] ;
644- } else if ( ! callback ) {
643+ } else if ( typeof callback === 'undefined' ) {
645644 if ( typeof args [ args . length - 1 ] === 'function' ) {
646645 callback = args . pop ( ) ;
647646 } else if ( typeof args [ args . length - 1 ] === 'undefined' ) {
@@ -689,12 +688,15 @@ RedisClient.prototype.send_command = function (command, args, callback) {
689688 'Please handle this in your code to make sure everything works as you intended it to behave.' , command . toUpperCase ( )
690689 ) ;
691690 args [ i ] = 'undefined' ; // Backwards compatible :/
691+ } else {
692+ args [ i ] = String ( args [ i ] ) ;
692693 }
693694 }
694695
695696 command_obj = new Command ( command , args , buffer_args , callback ) ;
696697
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 ) {
698700 if ( this . closing || ! this . enable_offline_queue ) {
699701 command = command . toUpperCase ( ) ;
700702 if ( ! this . closing ) {
@@ -717,7 +719,7 @@ RedisClient.prototype.send_command = function (command, args, callback) {
717719 }
718720
719721 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
721723 } else if ( command === 'monitor' ) {
722724 this . monitoring = true ;
723725 } else if ( command === 'quit' ) {
@@ -740,7 +742,7 @@ RedisClient.prototype.send_command = function (command, args, callback) {
740742 // This means that using Buffers in commands is going to be slower, so use Strings if you don't already have a Buffer.
741743 command_str = '*' + ( args . length + 1 ) + '\r\n$' + command . length + '\r\n' + command + '\r\n' ;
742744
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
744746 for ( i = 0 ; i < args . length ; i += 1 ) {
745747 arg = args [ i ] ;
746748 command_str += '$' + Buffer . byteLength ( arg ) + '\r\n' + arg + '\r\n' ;
@@ -890,7 +892,6 @@ commands.list.forEach(function (command) {
890892 }
891893 return this . send_command ( command , arr ) ;
892894 } ;
893-
894895 Multi . prototype [ command . toUpperCase ( ) ] = Multi . prototype [ command ] = function ( key , arg , callback ) {
895896 if ( Array . isArray ( key ) ) {
896897 if ( arg ) {
@@ -1031,7 +1032,7 @@ RedisClient.prototype.hmset = RedisClient.prototype.HMSET = function (key, args,
10311032 return this . send_command ( 'hmset' , tmp_args , callback ) ;
10321033 }
10331034 var len = arguments . length ;
1034- var tmp_args = new Array ( len ) ;
1035+ tmp_args = new Array ( len ) ;
10351036 for ( var i = 0 ; i < len ; i += 1 ) {
10361037 tmp_args [ i ] = arguments [ i ] ;
10371038 }
@@ -1050,10 +1051,7 @@ Multi.prototype.hmset = Multi.prototype.HMSET = function (key, args, callback) {
10501051 args = args . concat ( [ callback ] ) ;
10511052 }
10521053 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' ) ) {
10571055 tmp_args = [ 'hmset' , key ] ;
10581056 var fields = Object . keys ( args ) ;
10591057 while ( field = fields . shift ( ) ) {
@@ -1065,7 +1063,7 @@ Multi.prototype.hmset = Multi.prototype.HMSET = function (key, args, callback) {
10651063 }
10661064 } else {
10671065 var len = arguments . length ;
1068- var tmp_args = new Array ( len ) ;
1066+ tmp_args = new Array ( len ) ;
10691067 tmp_args [ 0 ] = 'hmset' ;
10701068 for ( var i = 0 ; i < len ; i += 1 ) {
10711069 tmp_args [ i + 1 ] = arguments [ i ] ;
0 commit comments