@@ -5,6 +5,7 @@ var net = require("net"),
5
5
util = require ( "util" ) ,
6
6
utils = require ( "./lib/utils" ) ,
7
7
Queue = require ( "./lib/queue" ) ,
8
+ Command = require ( "./lib/command" ) ,
8
9
events = require ( "events" ) ,
9
10
parsers = [ ] ,
10
11
// This static list of commands is updated from time to time.
@@ -277,14 +278,14 @@ RedisClient.prototype.init_parser = function () {
277
278
// That way the result / error won't stay in a try catch block and catch user things
278
279
this . reply_parser . send_error = function ( data ) {
279
280
process . nextTick ( function ( ) {
280
- this . return_error ( data ) ;
281
- } . bind ( this ) ) ;
282
- } . bind ( this ) ;
281
+ self . return_error ( data ) ;
282
+ } ) ;
283
+ } ;
283
284
this . reply_parser . send_reply = function ( data ) {
284
285
process . nextTick ( function ( ) {
285
- this . return_reply ( data ) ;
286
- } . bind ( this ) ) ;
287
- } . bind ( this ) ;
286
+ self . return_reply ( data ) ;
287
+ } ) ;
288
+ } ;
288
289
} ;
289
290
290
291
RedisClient . prototype . on_ready = function ( ) {
@@ -498,7 +499,6 @@ RedisClient.prototype.connection_gone = function (why) {
498
499
this . retry_timer = setTimeout ( retry_connection , this . retry_delay , this ) ;
499
500
} ;
500
501
501
- var err_code = / ^ ( [ A - Z ] + ) \s + ( .+ ) $ / ;
502
502
RedisClient . prototype . return_error = function ( err ) {
503
503
var command_obj = this . command_queue . shift ( ) , queue_len = this . command_queue . length ;
504
504
// send_command might have been used wrong => catch those cases too
@@ -508,7 +508,7 @@ RedisClient.prototype.return_error = function (err) {
508
508
err . command = command_obj . command ;
509
509
}
510
510
511
- var match = err . message . match ( err_code ) ;
511
+ var match = err . message . match ( utils . errCode ) ;
512
512
// LUA script could return user errors that don't behave like all other errors!
513
513
if ( match ) {
514
514
err . code = match [ 1 ] ;
@@ -537,7 +537,7 @@ RedisClient.prototype.return_reply = function (reply) {
537
537
// If the "reply" here is actually a message received asynchronously due to a
538
538
// pubsub subscription, don't pop the command queue as we'll only be consuming
539
539
// 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 ] ) {
541
541
type = reply [ 0 ] . toString ( ) ;
542
542
}
543
543
@@ -613,6 +613,7 @@ RedisClient.prototype.return_reply = function (reply) {
613
613
if ( Buffer . isBuffer ( reply ) ) {
614
614
reply = reply . toString ( ) ;
615
615
}
616
+ // If in monitoring mode only two commands are valid ones: AUTH and MONITOR wich reply with OK
616
617
len = reply . indexOf ( " " ) ;
617
618
timestamp = reply . slice ( 0 , len ) ;
618
619
argindex = reply . indexOf ( '"' ) ;
@@ -627,16 +628,6 @@ RedisClient.prototype.return_reply = function (reply) {
627
628
}
628
629
} ;
629
630
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
-
640
631
RedisClient . prototype . send_command = function ( command , args , callback ) {
641
632
var arg , command_obj , i , elem_count , buffer_args , stream = this . stream , command_str = "" , buffered_writes = 0 , err ;
642
633
@@ -842,8 +833,6 @@ function Multi(client, args) {
842
833
}
843
834
}
844
835
845
- exports . Multi = Multi ;
846
-
847
836
commands . forEach ( function ( fullCommand ) {
848
837
var command = fullCommand . split ( ' ' ) [ 0 ] ;
849
838
@@ -1045,7 +1034,7 @@ Multi.prototype.execute_callback = function (err, replies) {
1045
1034
1046
1035
// If we asked for strings, even in detect_buffers mode, then return strings:
1047
1036
if ( replies [ i ] instanceof Error ) {
1048
- var match = replies [ i ] . message . match ( err_code ) ;
1037
+ var match = replies [ i ] . message . match ( utils . errCode ) ;
1049
1038
// LUA script could return user errors that don't behave like all other errors!
1050
1039
if ( match ) {
1051
1040
replies [ i ] . code = match [ 1 ] ;
@@ -1132,10 +1121,5 @@ exports.createClient = function(port_arg, host_arg, options) {
1132
1121
throw new Error ( 'Unknown type of connection in createClient()' ) ;
1133
1122
} ;
1134
1123
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