Created
July 13, 2011 22:40
-
-
Save csanz/1081498 to your computer and use it in GitHub Desktop.
Pushing Sessions to Redis w/ Nodejs and Express
This file contains hidden or 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
| /* See instructions below */ | |
| var express = require('express') | |
| , RedisStore = require('connect-redis')(express); | |
| var app = express.createServer(); | |
| app.configure(function(){ | |
| this | |
| .use(express.cookieParser()) | |
| .use(express.errorHandler({dumpException: true, showStack: true})) | |
| .use(express.session({ secret: 'p!550ff', store: new RedisStore({ | |
| cookie: {domain: '.localhost.domain.com'} | |
| , db: 1 | |
| }) })) | |
| }); | |
| app.get('/', function(req, res, next){ | |
| req.session.testing = 'hello redis, how are you' | |
| res.send('ok'); | |
| }); | |
| app.listen(4000); | |
| console.log('listening on port 4000'); | |
| /* | |
| >> To install the above | |
| - Create server.js | |
| - Create package.json (See below) | |
| - Run npm install | |
| - Run node server.js | |
| - Connect to redis and run MONITOR (See below) | |
| - Run curl localhost 4000 | |
| >> To Test Redis: | |
| $telnet localhost 6379 | |
| Trying 127.0.0.1... | |
| Connected to localhost. | |
| Escape character is '^]'. | |
| >MONITOR <enter> | |
| >> Sample Package.json | |
| { "name": "redis-test" | |
| , "version": "0.0.1" | |
| , "dependencies": | |
| { "express" : "2.3.2" | |
| , "connect-redis" : "1.0.x" | |
| } | |
| , "main": "./server.js" | |
| , "engines": { | |
| "node": "0.4.x" | |
| , "npm" : "1.0.x" | |
| } | |
| } | |
| */ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment