# connect-multi-redis

> Manages multiple redis hosts for sessions

Latest version **0.2.0** (published 2013-04-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install connect-multi-redis
pnpm add connect-multi-redis
yarn add connect-multi-redis
bun add connect-multi-redis
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2013-04-04 |
| First published | 2013-04-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Robert Kowalski |
| Maintainers | robertkowalski |
| Keywords | redis, connect, express, session |

## Links

- npm: https://www.npmjs.com/package/connect-multi-redis
- Repository: https://github.com/robertkowalski/connect-multi-redis
- Issues: https://github.com/robertkowalski/connect-multi-redis/issues
- npm.io page: https://npm.io/package/connect-multi-redis

## Dependencies (1)

- [connect-redis](https://npm.io/package/connect-redis.md) 1.4.5

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 0.2.0 (latest) — 2013-04-04
- 0.1.1 — 2013-04-01
- 0.1.0 — 2013-04-01

## README

[![Build Status](https://travis-ci.org/robertkowalski/connect-multi-redis.png?branch=master)](https://travis-ci.org/robertkowalski/connect-multi-redis)

## 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:

```javascript

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:

```javascript

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'));
});

```

---
_Source: https://npm.io/package/connect-multi-redis · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
