-
-
Save grantmichaels/2690125 to your computer and use it in GitHub Desktop.
Setup Redis as Node.js Express Session Storage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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