Permalink
Browse files

Better AUTH

  • Loading branch information...
1 parent 454b2a3 commit 6bd29166ff1d7c1ccdab9a0df523403344950e9c @tim-smart tim-smart committed Jan 27, 2011
Showing with 12 additions and 17 deletions.
  1. +7 −1 deps/node-redis/index.js
  2. +2 −1 deps/node-redis/package.json
  3. +3 −15 index.js
View
@@ -2,9 +2,10 @@ var net = require('net'),
utils = require('./utils'),
Parser = require('./parser');
-var RedisClient = function RedisClient(port, host) {
+var RedisClient = function RedisClient(port, host, auth) {
this.host = host;
this.port = port;
+ this.auth = auth;
this.stream = net.createConnection(port, host);;
this.connected = false;
// Command queue.
@@ -34,6 +35,11 @@ var RedisClient = function RedisClient(port, host) {
self.stream.setTimeout(0);
self.connected = true;
+ // Send auth.
+ if (self.auth) {
+ self.sendCommand('AUTH', [self.auth], null);
+ }
+
// Resend commands if we need to.
var command,
commands = self.commands.array;
@@ -10,5 +10,6 @@
"type": "git",
"url": "http://github.com/Tim-Smart/node-redis.git"
},
- "engine": [ "node >=0.2.2" ]
+ "engine": [ "node >=0.2.2" ],
+ "main": "./"
}
View
@@ -28,13 +28,9 @@ var Queue = function (options) {
var self = this;
this.name = options.name;
- this.client = redis.createClient(options.port, options.host);
+ this.client = redis.createClient(options.port, options.host, options.auth);
this.prefix = options.prefix || '';
- if (options.auth) {
- this.client.auth(options.auth);
- }
-
this.client.on('error', function (error) {
self.emit('error', error);
});
@@ -111,11 +107,7 @@ var Worker = function (options) {
this.continual = false;
// Client for use with child jobs.
- this._child_client = redis.createClient(this.port, this.host);
-
- if (this.auth) {
- this._child_client.auth(this.auth);
- }
+ this._child_client = redis.createClient(this.port, this.host, this.auth);
this._child_client.on('error', function (error) {
self.emit('error', error);
@@ -173,11 +165,7 @@ Worker.prototype.next = function () {
Worker.prototype.start = function () {
var self = this;
- this.client = redis.createClient(this.port, this.host);
-
- if (this.auth) {
- this.client.auth(this.auth);
- }
+ this.client = redis.createClient(this.port, this.host, this.auth);
this.client.on('error', function (error) {
self.emit('error', error);

0 comments on commit 6bd2916

Please sign in to comment.