@@ -5,6 +5,7 @@ var net = require("net"),
55 util = require ( "util" ) ,
66 utils = require ( "./lib/utils" ) ,
77 Queue = require ( "./lib/queue" ) ,
8+ Command = require ( "./lib/command" ) ,
89 events = require ( "events" ) ,
910 parsers = [ ] ,
1011 // This static list of commands is updated from time to time.
@@ -277,14 +278,14 @@ RedisClient.prototype.init_parser = function () {
277278 // That way the result / error won't stay in a try catch block and catch user things
278279 this . reply_parser . send_error = function ( data ) {
279280 process . nextTick ( function ( ) {
280- this . return_error ( data ) ;
281- } . bind ( this ) ) ;
282- } . bind ( this ) ;
281+ self . return_error ( data ) ;
282+ } ) ;
283+ } ;
283284 this . reply_parser . send_reply = function ( data ) {
284285 process . nextTick ( function ( ) {
285- this . return_reply ( data ) ;
286- } . bind ( this ) ) ;
287- } . bind ( this ) ;
286+ self . return_reply ( data ) ;
287+ } ) ;
288+ } ;
288289} ;
289290
290291RedisClient . prototype . on_ready = function ( ) {
@@ -498,7 +499,6 @@ RedisClient.prototype.connection_gone = function (why) {
498499 this . retry_timer = setTimeout ( retry_connection , this . retry_delay , this ) ;
499500} ;
500501
501- var err_code = / ^ ( [ A - Z ] + ) \s + ( .+ ) $ / ;
502502RedisClient . prototype . return_error = function ( err ) {
503503 var command_obj = this . command_queue . shift ( ) , queue_len = this . command_queue . length ;
504504 // send_command might have been used wrong => catch those cases too
@@ -508,7 +508,7 @@ RedisClient.prototype.return_error = function (err) {
508508 err . command = command_obj . command ;
509509 }
510510
511- var match = err . message . match ( err_code ) ;
511+ var match = err . message . match ( utils . errCode ) ;
512512 // LUA script could return user errors that don't behave like all other errors!
513513 if ( match ) {
514514 err . code = match [ 1 ] ;
@@ -537,7 +537,7 @@ RedisClient.prototype.return_reply = function (reply) {
537537 // If the "reply" here is actually a message received asynchronously due to a
538538 // pubsub subscription, don't pop the command queue as we'll only be consuming
539539 // the head command prematurely.
540- if ( this . pub_sub_mode && Array . isArray ( reply ) && reply . length > 0 && reply [ 0 ] ) {
540+ if ( this . pub_sub_mode && Array . isArray ( reply ) && reply [ 0 ] ) {
541541 type = reply [ 0 ] . toString ( ) ;
542542 }
543543
@@ -613,6 +613,7 @@ RedisClient.prototype.return_reply = function (reply) {
613613 if ( Buffer . isBuffer ( reply ) ) {
614614 reply = reply . toString ( ) ;
615615 }
616+ // If in monitoring mode only two commands are valid ones: AUTH and MONITOR wich reply with OK
616617 len = reply . indexOf ( " " ) ;
617618 timestamp = reply . slice ( 0 , len ) ;
618619 argindex = reply . indexOf ( '"' ) ;
@@ -627,16 +628,6 @@ RedisClient.prototype.return_reply = function (reply) {
627628 }
628629} ;
629630
630- // This Command constructor is ever so slightly faster than using an object literal, but more importantly, using
631- // a named constructor helps it show up meaningfully in the V8 CPU profiler and in heap snapshots.
632- function Command ( command , args , sub_command , buffer_args , callback ) {
633- this . command = command ;
634- this . args = args ;
635- this . sub_command = sub_command ;
636- this . buffer_args = buffer_args ;
637- this . callback = callback ;
638- }
639-
640631RedisClient . prototype . send_command = function ( command , args , callback ) {
641632 var arg , command_obj , i , elem_count , buffer_args , stream = this . stream , command_str = "" , buffered_writes = 0 , err ;
642633
@@ -842,8 +833,6 @@ function Multi(client, args) {
842833 }
843834}
844835
845- exports . Multi = Multi ;
846-
847836commands . forEach ( function ( fullCommand ) {
848837 var command = fullCommand . split ( ' ' ) [ 0 ] ;
849838
@@ -1045,7 +1034,7 @@ Multi.prototype.execute_callback = function (err, replies) {
10451034
10461035 // If we asked for strings, even in detect_buffers mode, then return strings:
10471036 if ( replies [ i ] instanceof Error ) {
1048- var match = replies [ i ] . message . match ( err_code ) ;
1037+ var match = replies [ i ] . message . match ( utils . errCode ) ;
10491038 // LUA script could return user errors that don't behave like all other errors!
10501039 if ( match ) {
10511040 replies [ i ] . code = match [ 1 ] ;
@@ -1132,10 +1121,5 @@ exports.createClient = function(port_arg, host_arg, options) {
11321121 throw new Error ( 'Unknown type of connection in createClient()' ) ;
11331122} ;
11341123
1135- exports . print = function ( err , reply ) {
1136- if ( err ) {
1137- console . log ( "Error: " + err ) ;
1138- } else {
1139- console . log ( "Reply: " + reply ) ;
1140- }
1141- } ;
1124+ exports . print = utils . print ;
1125+ exports . Multi = Multi ;
0 commit comments