@@ -649,7 +649,7 @@ function Command(command, args, sub_command, buffer_args, callback) {
649649}
650650
651651RedisClient . prototype . send_command = function ( command , args , callback ) {
652- var arg , command_obj , i , elem_count , buffer_args , stream = this . stream , command_str = "" , buffered_writes = 0 ;
652+ var arg , command_obj , i , elem_count , buffer_args , stream = this . stream , command_str = "" , buffered_writes = 0 , err ;
653653
654654 // if (typeof callback === "function") {}
655655 // probably the fastest way:
@@ -686,7 +686,9 @@ RedisClient.prototype.send_command = function (command, args, callback) {
686686 return ;
687687 }
688688 if ( args [ args . length - 1 ] === undefined || args [ args . length - 1 ] === null ) {
689- var err = new Error ( 'send_command: ' + command + ' value must not be undefined or null' ) ;
689+ command = command . toUpperCase ( ) ;
690+ err = new Error ( 'send_command: ' + command + ' value must not be undefined or null' ) ;
691+ err . command_used = command ;
690692 if ( callback ) {
691693 return callback && callback ( err ) ;
692694 }
@@ -706,24 +708,25 @@ RedisClient.prototype.send_command = function (command, args, callback) {
706708 command_obj = new Command ( command , args , false , buffer_args , callback ) ;
707709
708710 if ( ! this . ready && ! this . send_anyway || ! stream . writable ) {
709- if ( this . enable_offline_queue ) {
710- if ( ! stream . writable ) {
711- debug ( "send command: stream is not writeable." ) ;
711+ if ( this . closing || ! this . enable_offline_queue ) {
712+ command = command . toUpperCase ( ) ;
713+ if ( ! this . closing ) {
714+ err = new Error ( command + ' can\'t be processed. Stream not writeable and enable_offline_queue is deactivated.' ) ;
715+ } else {
716+ err = new Error ( command + ' can\'t be processed. The connection has already been closed.' ) ;
717+ }
718+ err . command_used = command ;
719+ if ( callback ) {
720+ callback ( err ) ;
721+ } else {
722+ this . emit ( 'error' , err ) ;
712723 }
724+ } else {
713725 debug ( "Queueing " + command + " for next server connection." ) ;
714726 this . offline_queue . push ( command_obj ) ;
715727 this . should_buffer = true ;
716- } else {
717- var not_writeable_error = new Error ( 'send_command: stream not writeable. enable_offline_queue is false' ) ;
718- if ( command_obj . callback ) {
719- command_obj . callback ( not_writeable_error ) ;
720- } else {
721- this . emit ( "error" , not_writeable_error ) ;
722- return ;
723- }
724728 }
725-
726- return false ;
729+ return ;
727730 }
728731
729732 if ( command === "subscribe" || command === "psubscribe" || command === "unsubscribe" || command === "punsubscribe" ) {
0 commit comments