No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib api usage change Apr 4, 2013
test api usage change Apr 4, 2013
.gitignore init Mar 31, 2013
.npmignore
.travis.yml
LICENSE change to MIT license Apr 1, 2013
Makefile
README.md api usage change Apr 4, 2013
index.js rename module, bump version Apr 1, 2013
package.json

README.md

Build Status

connect-multi-redis

Manages multiple redis host fallbacks for sessions.

Once the connection to the current host fails, it choses another connected host, preventing the app from crashing.

If no redis hosts are connected it degrades to the builtin MemoryStore.

It also uses the MemoryStore if no config was provided.

Usage:

Place the middleware before the session-middleware of Connect or Express

Connect:

var connect = require('connect');
var http = require('http');
var RedisStore = require('connect-redis')(connect);

var options = {
  hosts: [
    new RedisStore({
      host: '127.0.0.1',
      port: 63793,
      maxAge: null
    }),
    new RedisStore({
      host: '127.0.0.1',
      port: 63793,
      maxAge: null
    }),
  ],
  session_secret: 'foo',
  cookie: {
    maxAge: null
  }
};

var app = connect();

var multipleRedisSessions = require('connect-multi-redis')(app, connect.session);

app
  .use(connect.cookieParser(options))
  .use(multipleRedisSessions())
  .use(connect.session({ store: options.hosts[0], secret: options.session_secret }))
  .use(function(req, res) {
    res.end('Hello World');
  });

var server = http.createServer(app).listen(3000);

Express:

var app = require('express');
var http = require('http');
var RedisStore = require('connect-redis')(express);

var options = {
  hosts: [
    new RedisStore({
      host: '127.0.0.1',
      port: 63793,
      maxAge: null
    }),
    new RedisStore({
      host: '127.0.0.1',
      port: 6379,
      maxAge: null
    }),
  ],
  session_secret: 'foo',
  cookie: {
    maxAge: null
  }
};

var multipleRedisSessions = require('connect-multi-redis')(app, express.session);

var app = express();

app.configure(function() {
  app.set('port', process.env.PORT || 3000);
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.favicon());
  app.use(express.logger('dev'));
  app.use(express.bodyParser());
  app.use(express.cookieParser(env.COOKIE_SECRET || 'lolcat'));
  app.use(multiRedis(options));
  app.use(express.session({ store: options.hosts[0], secret: env.SESSION_SECRET || 'lolcat' }));
  app.use(app.router);
});

app.get('/', function(req, res){
  res.send('hello world');
});

http.createServer(app).listen(app.get('port'), function() {
  console.log("Express server listening on port " + app.get('port'));
});