Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to inject redis clients into the Faye Redis engine. #13

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
33 changes: 23 additions & 10 deletions faye-redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,37 @@ var Engine = function(server, options) {
db = this._options.database || this.DEFAULT_DATABASE,
auth = this._options.password,
gc = this._options.gc || this.DEFAULT_GC,
client = this._options.client,
subscriberClient = this._options.subscriberClient,
socket = this._options.socket;

this._ns = this._options.namespace || '';

if (socket) {
this._redis = redis.createClient(socket, {no_ready_check: true});
this._subscriber = redis.createClient(socket, {no_ready_check: true});
if (client) {
this._redis = client;
} else {
this._redis = redis.createClient(port, host, {no_ready_check: true});
this._subscriber = redis.createClient(port, host, {no_ready_check: true});
this._redis = socket ?
redis.createClient(socket, {no_ready_check: true}) :
redis.createClient(port, host, {no_ready_check: true});

if (auth) {
this._redis.auth(auth);
}
this._redis.select(db);
}

if (auth) {
this._redis.auth(auth);
this._subscriber.auth(auth);
if (subscriberClient) {
this._subscriber = subscriberClient;
} else {
this._subscriber = socket ?
redis.createClient(socket, {no_ready_check: true}) :
redis.createClient(port, host, {no_ready_check: true});

if (auth) {
this._subscriber.auth(auth);
}
this._subscriber.select(db);
}
this._redis.select(db);
this._subscriber.select(db);

this._messageChannel = this._ns + '/notifications/messages';
this._closeChannel = this._ns + '/notifications/close';
Expand Down
49 changes: 29 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
{ "name" : "faye-redis"
, "description" : "Redis backend engine for Faye"
, "homepage" : "http://github.com/faye/faye-redis-node"
, "author" : "James Coglan <[email protected]> (http://jcoglan.com/)"
, "keywords" : ["pubsub", "bayeux"]
, "license" : "MIT"

, "version" : "0.2.0"
, "engines" : {"node": ">=0.4.0"}
, "main" : "./faye-redis"
, "dependencies" : {"redis": ""}
, "devDependencies" : {"jstest": ""}

, "scripts" : {"test": "node spec/runner.js"}

, "bugs" : "http://github.com/faye/faye-redis-node/issues"

, "repository" : { "type" : "git"
, "url" : "git://github.com/faye/faye-redis-node.git"
}
{
"name": "faye-redis",
"description": "Redis backend engine for Faye",
"homepage": "http://github.com/faye/faye-redis-node",
"author": "James Coglan <[email protected]> (http://jcoglan.com/)",
"keywords": [
"pubsub",
"bayeux"
],
"license": "MIT",
"version": "0.3.0",
"engines": {
"node": ">=0.4.0"
},
"main": "./faye-redis",
"dependencies": {
"redis": ""
},
"devDependencies": {
"jstest": ""
},
"scripts": {
"test": "node spec/runner.js"
},
"bugs": "http://github.com/faye/faye-redis-node/issues",
"repository": {
"type": "git",
"url": "git://github.com/faye/faye-redis-node.git"
}
}
18 changes: 18 additions & 0 deletions spec/faye_redis_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ JS.Test.describe("Redis engine", function() { with(this) {
itShouldBehaveLike("distributed engine")
}})

describe("using provided clients", function() { with(this) {
before(function() { with(this) {
var redis = require('redis');
var client = redis.createClient(6379, 'localhost', {no_ready_check: true})
var subscriberClient = redis.createClient(6379, 'localhost', {no_ready_check: true})

if(!process.env.TRAVIS) {
client.auth("foobared")
subscriberClient.auth("foobared")
}

this.engineOpts = {type: RedisEngine, client: client, subscriberClient: subscriberClient, namespace: new Date().getTime().toString()}
}})

itShouldBehaveLike("faye engine")
}})

if (process.env.TRAVIS) return

describe("using a Unix socket", function() { with(this) {
Expand All @@ -31,4 +48,5 @@ JS.Test.describe("Redis engine", function() { with(this) {

itShouldBehaveLike("faye engine")
}})

}})