diff --git a/faye-redis.js b/faye-redis.js index 3d6c4cb..69568fc 100644 --- a/faye-redis.js +++ b/faye-redis.js @@ -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'; diff --git a/package.json b/package.json index cafab30..b0c1f8f 100644 --- a/package.json +++ b/package.json @@ -1,21 +1,30 @@ -{ "name" : "faye-redis" -, "description" : "Redis backend engine for Faye" -, "homepage" : "http://github.com/faye/faye-redis-node" -, "author" : "James Coglan (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 (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" + } } diff --git a/spec/faye_redis_spec.js b/spec/faye_redis_spec.js index c9edf72..f34be69 100644 --- a/spec/faye_redis_spec.js +++ b/spec/faye_redis_spec.js @@ -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) { @@ -31,4 +48,5 @@ JS.Test.describe("Redis engine", function() { with(this) { itShouldBehaveLike("faye engine") }}) + }})