Skip to content

Commit

Permalink
RedisStore can have its users (e.g connect-session) handle connection…
Browse files Browse the repository at this point in the history
… to Redis problems
  • Loading branch information
louischatriot committed Aug 27, 2012
1 parent c20fa0b commit 889ffa1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/connect-redis.js
Expand Up @@ -42,6 +42,8 @@ module.exports = function(connect){
*/

function RedisStore(options) {
var self = this;

options = options || {};
Store.call(this, options);
this.prefix = null == options.prefix
Expand All @@ -58,18 +60,24 @@ module.exports = function(connect){
this.ttl = options.ttl;

if (options.db) {
var self = this;
self.client.select(options.db);
self.client.on("connect", function() {
self.client.send_anyways = true;
self.client.select(options.db);
self.client.send_anyways = false;
});
}

// Let users of the RedisStore handle connection to Redis issues if safe mode enabled
if (options.safeMode) {
self.client.on('error', function () { self.emit('connectionError'); });
self.client.on('connect', function () { self.emit('connectionEstablished'); });
}
};

/**
* Inherit from `Store`.
* Store is an EventEmitter so RedisStore is one too
*/

RedisStore.prototype.__proto__ = Store.prototype;
Expand Down

0 comments on commit 889ffa1

Please sign in to comment.