diff --git a/README.md b/README.md index c899ca6..4abc5da 100644 --- a/README.md +++ b/README.md @@ -66,11 +66,11 @@ configured. Then run: ## Initializing ## var Thoonk = require("thoonk").Thoonk; - var thoonk = new Thoonk(host, port, db) + var thoonk = new Thoonk(host, port, db, password) Or, you can use: - var thoonk = require("thoonk").createClient(host, port, db); + var thoonk = require("thoonk").createClient(host, port, db, password); ## Creating a Feed ## diff --git a/job.js b/job.js index ed2d7fd..2d6650f 100644 --- a/job.js +++ b/job.js @@ -74,6 +74,11 @@ var Feed = require("./feed.js").Feed, function Job(thoonk, name, config) { Feed.call(this, thoonk, name, config, 'job'); this.bredis = redis.createClient(this.thoonk.port, this.thoonk.host); + if (this.thoonk.password) { + this.bredis.auth(this.thoonk.password, function (err) { + if (err) { throw err; } + }); + } this.bredis.select(this.thoonk.db); this.publish = this.thoonk.lock.require(jobPublish, this); this.put = this.thoonk.lock.require(jobPublish, this); diff --git a/package.json b/package.json index d92af4b..7dca75f 100644 --- a/package.json +++ b/package.json @@ -9,5 +9,5 @@ "files": ["feed.js", "job.js", "queue.js", "sorted_feed.js", "testall.js", "thoonk.js", "tests", "examples", "LICENSE", "README.md", "contract.txt", "testconfig.json"], "main": "./thoonk.js", "repository": {"type": "git", "url": "http://github.com/fritzy/thoonk.js.git"}, - "dependencies": {"node-uuid": ">=1.1.0", "redis": ">=0.5.5", "padlock": ">=1.0.0"} + "dependencies": {"node-uuid": "1.4.0", "redis": "0.6.7", "padlock": "1.0.2"} } diff --git a/queue.js b/queue.js index 53c03c1..a9c365e 100644 --- a/queue.js +++ b/queue.js @@ -4,6 +4,7 @@ */ var Feed = require("./feed.js").Feed, + redis = require("redis"), uuid = require("node-uuid"); /** @@ -32,6 +33,11 @@ var Feed = require("./feed.js").Feed, function Queue(thoonk, name, config) { Feed.call(this, thoonk, name, config, 'queue'); this.bredis = redis.createClient(this.thoonk.port, this.thoonk.host); + if (this.thoonk.password) { + this.bredis.auth(this.thoonk.password, function (err) { + if (err) { throw err; } + }); + } this.bredis.select(this.thoonk.db); this.publish = this.thoonk.lock.require(queuePublish, this); this.put = this.thoonk.lock.require(queuePublish, this); diff --git a/testconfig.json b/testconfig.json index 9b7a833..ec80410 100644 --- a/testconfig.json +++ b/testconfig.json @@ -1 +1 @@ -{"enabled": false, "host": "localhost", "port": 6379, "db": 10 } +{"enabled": true, "host": "localhost", "port": 6379, "db": 0, "password": ""} diff --git a/tests/test_feeds.js b/tests/test_feeds.js index c74dd6c..df81cbe 100644 --- a/tests/test_feeds.js +++ b/tests/test_feeds.js @@ -16,7 +16,7 @@ var tests = new TestObject([ "hasId4:true", "hasId1:false", ], function(config) { - var thoonk = new Thoonk(config.host, config.port, config.db); + var thoonk = new Thoonk(config.host, config.port, config.db, config.password); tests.on("done", function() { thoonk.quit(); }); diff --git a/tests/test_jobs.js b/tests/test_jobs.js index c14e871..c9de26f 100644 --- a/tests/test_jobs.js +++ b/tests/test_jobs.js @@ -6,7 +6,7 @@ var tests = new TestObject([ "publish: item2", "publish: item3", ], function(config) { - var thoonk = new Thoonk(config.host, config.port, config.db); + var thoonk = new Thoonk(config.host, config.port, config.db, config.password); tests.on("done", function() { thoonk.quit(); }); diff --git a/tests/test_lists.js b/tests/test_lists.js index 1eaf7b2..1cf2b3d 100644 --- a/tests/test_lists.js +++ b/tests/test_lists.js @@ -19,7 +19,7 @@ var tests = new TestObject([ "position:6 :end", 'edit:6: neehawedit', ], function(config) { - var thoonk = new Thoonk(config.host, config.port, config.db); + var thoonk = new Thoonk(config.host, config.port, config.db, config.password); tests.on("done", function() { thoonk.quit(); }); diff --git a/thoonk.js b/thoonk.js index f5c59ba..7589982 100644 --- a/thoonk.js +++ b/thoonk.js @@ -20,19 +20,33 @@ var Feed = exports.Feed = require("./feed.js").Feed, * * @param host * @param port + * @param db + * @param password */ -var Thoonk = exports.Thoonk = function Thoonk(host, port, db) { +var Thoonk = exports.Thoonk = function Thoonk(host, port, db, password) { host || (host = "127.0.0.1"); port || (port = 6379); db || (db = 0); + password || (password = ""); this.host = host; this.port = port; this.db = db; + this.password = password; EventEmitter.call(this); this.lredis = redis.createClient(port, host); + if (password) { + this.lredis.auth(password, function (err) { + if (err) { throw err; } + }); + } this.lredis.select(db); this.lredis.subscribe("newfeed", "delfeed", "conffeed"); this.mredis = redis.createClient(port, host); + if (password) { + this.mredis.auth(password, function (err) { + if (err) { throw err; } + }); + } this.mredis.select(db); this.lock = new padlock.Padlock(); @@ -416,10 +430,10 @@ Thoonk.prototype.getFeedNames = function(callback, error_callback) { * Shortcut function to make creating a Thoonk instance * easier, as so: * - * var pubsub = require("thoonk").createClient(host, port, db); + * var pubsub = require("thoonk").createClient(host, port, db, password); */ -exports.createClient = function(host, port, db) { - return new Thoonk(host, port, db); +exports.createClient = function(host, port, db, password) { + return new Thoonk(host, port, db, password); } -exports.VERSION = '0.5.1'; +exports.VERSION = '0.5.3';