Skip to content
Myr

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 file

Take it

The walk stopped after 200 commits: lines older than fda31b7 point at it.

Added simple web-service exampleTj Holowaychukbefore adoptionfda31b7

lines 1–7why, one step back
1
2/**3 * Module dependencies.4 */56var express = require('../../lib/express');7

fixed connect-redis exampleTj Holowaychukbefore adoption8f87c50

lines 8–10why, one step back
8// pass the express to the connect redis module
9// allowing it to inherit from express.session.Store10var RedisStore = require('connect-redis')(express);

Added simple web-service exampleTj Holowaychukbefore adoptionfda31b7

line 11why, one step back
11

fixed connect-redis exampleTj Holowaychukbefore adoption8f87c50

line 12why, one step back
12var app = express.createServer();

Added simple web-service exampleTj Holowaychukbefore adoptionfda31b7

line 13why, one step back
13

fixed connect-redis exampleTj Holowaychukbefore adoption8f87c50

line 14why, one step back
14app.use(express.favicon());

Added simple web-service exampleTj Holowaychukbefore adoptionfda31b7

line 15why, one step back
15

fixed connect-redis exampleTj Holowaychukbefore adoption8f87c50

lines 16–27why, one step back
16// request logging
17app.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 }));

Added simple web-service exampleTj Holowaychukbefore adoptionfda31b7

lines 28–41why, one step back
28
29app.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');