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

Already on GitHub? Sign in to your account

Add support to use an existing Redis client connection #14

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+13 −6
Split
View
@@ -28,12 +28,19 @@ var oneDay = 86400;
var RedisStore = module.exports = function RedisStore(options) {
options = options || {};
Store.call(this, options);
- this.client = new redis.createClient(options.port, options.host, options);
- if (options.db) {
- var self = this;
- self.client.on('connect', function() {
- self.client.select(options.db);
- });
+ if (options.client) {
+ this.client = options.client;
+ if (options.db) {
+ this.client.select(options.db);
+ }
+ } else {
+ this.client = new redis.createClient(options.port, options.host, options);
+ if (options.db) {
+ var self = this;
+ self.client.on('connect', function() {
+ self.client.select(options.db);
+ });
+ }
}
};