Skip to content

Commit

Permalink
Merge pull request tj#54 from louischatriot/master
Browse files Browse the repository at this point in the history
RedisStore can have its users (e.g connect-session) handle connection to Redis problems
  • Loading branch information
tj committed Sep 5, 2012
2 parents c20fa0b + 8b78de5 commit 07f98c3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/connect-redis.js
Original file line number Diff line number Diff line change
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,14 +60,17 @@ 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
self.client.on('error', function () { self.emit('disconnect'); });
self.client.on('connect', function () { self.emit('connect'); });
};

/**
Expand Down

0 comments on commit 07f98c3

Please sign in to comment.