4
4
5
5
var net = require ( "net" ) ,
6
6
URL = require ( "url" ) ,
7
- util = require ( "./lib/ util" ) ,
7
+ util = require ( "util" ) ,
8
8
Queue = require ( "./lib/queue" ) ,
9
9
to_array = require ( "./lib/to_array" ) ,
10
10
events = require ( "events" ) ,
@@ -199,6 +199,9 @@ RedisClient.prototype.on_error = function (msg) {
199
199
this . connection_gone ( "error" ) ;
200
200
} ;
201
201
202
+ var noPasswordIsSet = / n o p a s s w o r d i s s e t / ;
203
+ var loading = / L O A D I N G / ;
204
+
202
205
RedisClient . prototype . do_auth = function ( ) {
203
206
var self = this ;
204
207
@@ -207,14 +210,14 @@ RedisClient.prototype.do_auth = function () {
207
210
self . send_anyway = true ;
208
211
self . send_command ( "auth" , [ this . auth_pass ] , function ( err , res ) {
209
212
if ( err ) {
210
- if ( err . toString ( ) . match ( "LOADING" ) ) {
213
+ if ( loading . test ( err . message ) ) {
211
214
// if redis is still loading the db, it will not authenticate and everything else will fail
212
215
console . log ( "Redis still loading, trying to authenticate later" ) ;
213
216
setTimeout ( function ( ) {
214
217
self . do_auth ( ) ;
215
218
} , 2000 ) ; // TODO - magic number alert
216
219
return ;
217
- } else if ( err . toString ( ) . match ( "no password is set" ) ) {
220
+ } else if ( noPasswordIsSet . test ( err . message ) ) {
218
221
console . log ( "Warning: Redis server does not require a password, but a password was supplied." ) ;
219
222
err = null ;
220
223
res = "OK" ;
@@ -302,11 +305,7 @@ RedisClient.prototype.init_parser = function () {
302
305
303
306
// "reply error" is an error sent back by Redis
304
307
this . reply_parser . on ( "reply error" , function ( reply ) {
305
- if ( reply instanceof Error ) {
306
- self . return_error ( reply ) ;
307
- } else {
308
- self . return_error ( new Error ( reply ) ) ;
309
- }
308
+ self . return_error ( reply ) ;
310
309
} ) ;
311
310
this . reply_parser . on ( "reply" , function ( reply ) {
312
311
self . return_reply ( reply ) ;
@@ -654,7 +653,9 @@ RedisClient.prototype.return_reply = function (reply) {
654
653
}
655
654
656
655
try_callback ( command_obj . callback , reply ) ;
657
- } else debug ( "no callback for reply: " + ( reply && reply . toString && reply . toString ( ) ) ) ;
656
+ } else {
657
+ debug ( "no callback for reply: " + ( reply && reply . toString && reply . toString ( ) ) ) ;
658
+ }
658
659
} else if ( this . pub_sub_mode || ( command_obj && command_obj . sub_command ) ) {
659
660
if ( Array . isArray ( reply ) ) {
660
661
type = reply [ 0 ] . toString ( ) ;
0 commit comments