diff --git a/lib/manager.js b/lib/manager.js index ff444d3795..2f9ff7d140 100644 --- a/lib/manager.js +++ b/lib/manager.js @@ -88,14 +88,18 @@ function Manager (server, options) { this.settings[i] = options[i]; } + var self = this; + this.initStore(); + this.on('set:store', function() { + self.initStore(); + }); + // reset listeners this.oldListeners = server.listeners('request'); server.removeAllListeners('request'); - var self = this; - server.on('request', function (req, res) { self.handleRequest(req, res); }); diff --git a/lib/stores/redis.js b/lib/stores/redis.js index 26f7a9207b..d4818950fc 100644 --- a/lib/stores/redis.js +++ b/lib/stores/redis.js @@ -60,12 +60,28 @@ function Redis (opts) { } } - var redis = opts.redis || require('redis'); + var redis = opts.redis || require('redis') + , RedisClient = redis.RedisClient; // initialize a pubsub client and a regular client - this.pub = redis.createClient(opts.redisPub); - this.sub = redis.createClient(opts.redisSub); - this.cmd = redis.createClient(opts.redisClient); + if (opts.redisPub instanceof RedisClient) { + this.pub = opts.redisPub; + } else { + opts.redisPub || (opts.redisPub = {}); + this.pub = redis.createClient(opts.redisPub.port, opts.redisPub.host, opts.redisPub); + } + if (opts.redisSub instanceof RedisClient) { + this.sub = opts.redisSub; + } else { + opts.redisSub || (opts.redisSub = {}); + this.sub = redis.createClient(opts.redisSub.port, opts.redisSub.host, opts.redisSub); + } + if (opts.redisClient instanceof RedisClient) { + this.cmd = opts.redisClient; + } else { + opts.redisClient || (opts.redisClient = {}); + this.cmd = redis.createClient(opts.redisClient.port, opts.redisClient.host, opts.redisClient); + } Store.call(this, opts); }; @@ -118,7 +134,7 @@ Redis.prototype.subscribe = function (name, consumer, fn) { self.on('unsubscribe', function unsubscribe (ch) { if (name == ch) { self.sub.removeListener('message', message); - self.removeEvent('unsubscribe', unsubscribe); + self.removeListener('unsubscribe', unsubscribe); } });