diff --git a/Readme.md b/Readme.md index e7566878..10dbb686 100644 --- a/Readme.md +++ b/Readme.md @@ -196,6 +196,25 @@ jobs.process('slideshow pdf', 5, function(job, done){ }); ``` +## Redis Connection Settings + + By default, Kue will connect to Redis using the client default settings (port defaults to `6389`, host defaults to `127.0.0.1`). Redis client connection settings can be set by overriding the `kue.redis.createConnection` function. + + For example, to create a Redis client that connects to `192.168.1.2` on port `1234` that requires authentication, use the following: + + ```javascript + var kue = require('kue') + , redis = require('redis'); + + kue.redis.createClient = function() { + var client = redis.createClient(1234, '192.168.1.2'); + client.auth('YOUR_PASSWORD'); + return client; + } + ``` + + Redis connection settings must be set before calling `kue.createQueue()` or accessing `kue.app`. + ## User-Interface The UI is a small [Express](http://github.com/visionmedia/express) application, to fire it up simply run the following, altering the port etc as desired. @@ -348,4 +367,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/lib/kue.js b/lib/kue.js index 745c29f2..7b844e97 100644 --- a/lib/kue.js +++ b/lib/kue.js @@ -13,7 +13,7 @@ var EventEmitter = require('events').EventEmitter , Worker = require('./queue/worker') , events = require('./queue/events') , Job = require('./queue/job') - , redis = require('redis'); + , redis = require('./redis'); /** * Expose `Queue`. @@ -33,11 +33,25 @@ exports.version = '0.1.0'; exports.Job = Job; +/** + * Server instance (that is lazily required) + */ + +var app; + /** * Expose the server. */ -exports.app = require('./http'); +Object.defineProperty(exports, 'app', { + get: function() { return app || (app = require('./http')); } +}); + +/** + * Expose the RedisClient factory. + */ + +exports.redis = redis; /** * Create a new `Queue`. diff --git a/lib/queue/pool.js b/lib/queue/pool.js index cc578417..f4e04823 100644 --- a/lib/queue/pool.js +++ b/lib/queue/pool.js @@ -9,7 +9,7 @@ * Module dependencies. */ -var redis = require('redis'); +var redis = require('../redis'); /** * Max connections in the pool. @@ -49,4 +49,5 @@ exports.alloc = function(){ exports.pubsubClient = function(){ return exports._pubsub || (exports._pubsub = redis.createClient()); -}; \ No newline at end of file +}; + diff --git a/lib/queue/worker.js b/lib/queue/worker.js index 78f28425..482d16db 100644 --- a/lib/queue/worker.js +++ b/lib/queue/worker.js @@ -10,7 +10,7 @@ */ var EventEmitter = require('events').EventEmitter - , redis = require('redis') + , redis = require('../redis') , Job = require('./job') , events = require('./events'); diff --git a/lib/redis.js b/lib/redis.js new file mode 100644 index 00000000..708d16c7 --- /dev/null +++ b/lib/redis.js @@ -0,0 +1,24 @@ + +/*! + * kue - RedisClient factory + * Copyright (c) 2011 LearnBoost + * MIT Licensed + * Author: bitprobe@gmail.com + */ + +/** + * Module dependencies. + */ +var redis = require('redis'); + +/** + * Create a RedisClient + * + * @return {RedisClient} + * @api private + */ + +exports.createClient = function() { + return redis.createClient(); +}; +