@@ -661,7 +661,7 @@ function Command(command, args, sub_command, buffer_args, callback) {
661661}
662662
663663RedisClient . prototype . send_command = function ( command , args , callback ) {
664- var arg , command_obj , i , elem_count , buffer_args , stream = this . stream , command_str = "" , buffered_writes = 0 ;
664+ var arg , command_obj , i , elem_count , buffer_args , stream = this . stream , command_str = "" , buffered_writes = 0 , err ;
665665
666666 // if (typeof callback === "function") {}
667667 // probably the fastest way:
@@ -698,7 +698,9 @@ RedisClient.prototype.send_command = function (command, args, callback) {
698698 return ;
699699 }
700700 if ( args [ args . length - 1 ] === undefined || args [ args . length - 1 ] === null ) {
701- var err = new Error ( 'send_command: ' + command + ' value must not be undefined or null' ) ;
701+ command = command . toUpperCase ( ) ;
702+ err = new Error ( 'send_command: ' + command + ' value must not be undefined or null' ) ;
703+ err . command_used = command ;
702704 if ( callback ) {
703705 return callback && callback ( err ) ;
704706 }
@@ -718,24 +720,25 @@ RedisClient.prototype.send_command = function (command, args, callback) {
718720 command_obj = new Command ( command , args , false , buffer_args , callback ) ;
719721
720722 if ( ! this . ready && ! this . send_anyway || ! stream . writable ) {
721- if ( this . enable_offline_queue ) {
722- if ( ! stream . writable ) {
723- debug ( "send command: stream is not writeable." ) ;
723+ if ( this . closing || ! this . enable_offline_queue ) {
724+ command = command . toUpperCase ( ) ;
725+ if ( ! this . closing ) {
726+ err = new Error ( command + ' can\'t be processed. Stream not writeable and enable_offline_queue is deactivated.' ) ;
727+ } else {
728+ err = new Error ( command + ' can\'t be processed. The connection has already been closed.' ) ;
729+ }
730+ err . command_used = command ;
731+ if ( callback ) {
732+ callback ( err ) ;
733+ } else {
734+ this . emit ( 'error' , err ) ;
724735 }
736+ } else {
725737 debug ( "Queueing " + command + " for next server connection." ) ;
726738 this . offline_queue . push ( command_obj ) ;
727739 this . should_buffer = true ;
728- } else {
729- var not_writeable_error = new Error ( 'send_command: stream not writeable. enable_offline_queue is false' ) ;
730- if ( command_obj . callback ) {
731- command_obj . callback ( not_writeable_error ) ;
732- } else {
733- this . emit ( "error" , not_writeable_error ) ;
734- return ;
735- }
736740 }
737-
738- return false ;
741+ return ;
739742 }
740743
741744 if ( command === "subscribe" || command === "psubscribe" || command === "unsubscribe" || command === "punsubscribe" ) {
0 commit comments