Skip to content

Commit 1468917

Browse files
committed
Merge pull request #529 from dshaw/patch/redisstore
Fix RedisStore
2 parents b2f9f19 + c6b3549 commit 1468917

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

lib/manager.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,18 @@ function Manager (server, options) {
8888
this.settings[i] = options[i];
8989
}
9090

91+
var self = this;
92+
9193
this.initStore();
9294

95+
this.on('set:store', function() {
96+
self.initStore();
97+
});
98+
9399
// reset listeners
94100
this.oldListeners = server.listeners('request');
95101
server.removeAllListeners('request');
96102

97-
var self = this;
98-
99103
server.on('request', function (req, res) {
100104
self.handleRequest(req, res);
101105
});

lib/stores/redis.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,28 @@ function Redis (opts) {
6060
}
6161
}
6262

63-
var redis = opts.redis || require('redis');
63+
var redis = opts.redis || require('redis')
64+
, RedisClient = redis.RedisClient;
6465

6566
// initialize a pubsub client and a regular client
66-
this.pub = redis.createClient(opts.redisPub);
67-
this.sub = redis.createClient(opts.redisSub);
68-
this.cmd = redis.createClient(opts.redisClient);
67+
if (opts.redisPub instanceof RedisClient) {
68+
this.pub = opts.redisPub;
69+
} else {
70+
opts.redisPub || (opts.redisPub = {});
71+
this.pub = redis.createClient(opts.redisPub.port, opts.redisPub.host, opts.redisPub);
72+
}
73+
if (opts.redisSub instanceof RedisClient) {
74+
this.sub = opts.redisSub;
75+
} else {
76+
opts.redisSub || (opts.redisSub = {});
77+
this.sub = redis.createClient(opts.redisSub.port, opts.redisSub.host, opts.redisSub);
78+
}
79+
if (opts.redisClient instanceof RedisClient) {
80+
this.cmd = opts.redisClient;
81+
} else {
82+
opts.redisClient || (opts.redisClient = {});
83+
this.cmd = redis.createClient(opts.redisClient.port, opts.redisClient.host, opts.redisClient);
84+
}
6985

7086
Store.call(this, opts);
7187
};
@@ -118,7 +134,7 @@ Redis.prototype.subscribe = function (name, consumer, fn) {
118134
self.on('unsubscribe', function unsubscribe (ch) {
119135
if (name == ch) {
120136
self.sub.removeListener('message', message);
121-
self.removeEvent('unsubscribe', unsubscribe);
137+
self.removeListener('unsubscribe', unsubscribe);
122138
}
123139
});
124140

0 commit comments

Comments
 (0)