Skip to content

Instantly share code, notes, and snippets.

@grantmichaels
Forked from srohde/app.coffee
Created May 13, 2012 20:51
Show Gist options
  • Save grantmichaels/2690125 to your computer and use it in GitHub Desktop.
Save grantmichaels/2690125 to your computer and use it in GitHub Desktop.
Setup Redis as Node.js Express Session Storage
express = require 'express'
RedisStore = require('connect-redis')(express)
# Heroku redistogo connection
if process.env.REDISTOGO_URL
rtg = require('url').parse process.env.REDISTOGO_URL
redis = require('redis').createClient rtg.port, rtg.hostname
redis.auth rtg.auth.split(':')[1] # auth 1st part is username and 2nd is password separated by ":"
# Localhost
else
redis = require("redis").createClient()
# Create express application
app = module.exports = express.createServer(
express.cookieParser(),
express.session
secret: process.env.CLIENT_SECRET or "super secret string"
maxAge : new Date Date.now() + 7200000 # 2h Session lifetime
store: new RedisStore {client: redis}
express.query()
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment