Skip to content
This repository was archived by the owner on Jan 10, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ##

Expand Down
5 changes: 5 additions & 0 deletions job.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
}
6 changes: 6 additions & 0 deletions queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

var Feed = require("./feed.js").Feed,
redis = require("redis"),
uuid = require("node-uuid");

/**
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion testconfig.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"enabled": false, "host": "localhost", "port": 6379, "db": 10 }
{"enabled": true, "host": "localhost", "port": 6379, "db": 0, "password": ""}
2 changes: 1 addition & 1 deletion tests/test_feeds.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
2 changes: 1 addition & 1 deletion tests/test_jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
2 changes: 1 addition & 1 deletion tests/test_lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
24 changes: 19 additions & 5 deletions thoonk.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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';