redis.js
This file
Path
examples/session/redis.js
41 lines · 977 bytes · JavaScript
Last changed by
fixed connect-redis exampleTj Holowaychukbefore adoption8f87c50
History of this fileTake it
The walk stopped after 200 commits: lines older than 99b49d2 point at it.
updated docsTj Holowaychukbefore adoption99b49d2
lines 1–7why, one step back12/**3 * Module dependencies.4 */56var express = require('../../lib/express');7fixed connect-redis exampleTj Holowaychukbefore adoption8f87c50
lines 8–10why, one step back8// pass the express to the connect redis module9// allowing it to inherit from express.session.Store10var RedisStore = require('connect-redis')(express);updated docsTj Holowaychukbefore adoption99b49d2
line 11why, one step back11fixed connect-redis exampleTj Holowaychukbefore adoption8f87c50
line 12why, one step back12var app = express.createServer();updated docsTj Holowaychukbefore adoption99b49d2
line 13why, one step back13fixed connect-redis exampleTj Holowaychukbefore adoption8f87c50
line 14why, one step back14app.use(express.favicon());updated docsTj Holowaychukbefore adoption99b49d2
line 15why, one step back15fixed connect-redis exampleTj Holowaychukbefore adoption8f87c50
lines 16–27why, one step back16// request logging17app.use(express.logger());1819// required to parse the session cookie20app.use(express.cookieParser());2122// Populates:23// - req.session24// - req.sessionStore25// - req.sessionID (or req.session.id)2627app.use(express.session({ secret: 'keyboard cat', store: new RedisStore }));updated docsTj Holowaychukbefore adoption99b49d2
lines 28–41why, one step back2829app.get('/', function(req, res){30 var body = '';31 if (req.session.views) {32 ++req.session.views;33 } else {34 req.session.views = 1;35 body += '<p>First time visiting? view this page in several browsers :)</p>';36 }37 res.send(body + '<p>viewed <strong>' + req.session.views + '</strong> times.</p>');38});3940app.listen(3000);41console.log('Express app started on port 3000');