Skip to content

Instantly share code, notes, and snippets.

@mayuroks
Created February 6, 2014 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mayuroks/8836447 to your computer and use it in GitHub Desktop.
Save mayuroks/8836447 to your computer and use it in GitHub Desktop.
Redis express
var http = require('http'), express = require('express'), redis = require('redis'), RedisStore = require('connect-redis')(express); var redisClient = redis.createClient( 17969, '<redacted>.garantiadata.com', { auth_pass: '<redacted>' } ); var app = express(); app.use(express.cookieParser('pure cat flight grass')); app.use(express.session({ store: new RedisStore({ client: redisClient }) })); app.use(express.urlencoded()); app.use(app.router); app.get('/', function(req, res){ var html = ''; if(req.session.name) html += '<p>Welcome, ' + req.session.name + '.</p>'; html += '<form method="POST"><p>Name: ' + '<input type="text" name="name"> ' + '<input type="submit"></p></form>'; res.send(html); }); app.post('/', function(req, res){ req.session.name = req.body.name; res.redirect('/'); }); http.createServer(app).listen(3000,function(){ console.log('listening on 3000'); });
I'm using a free Redis account from Garantia Data, not that that should make a difference. Do you spot any differences between what I'm doing and what you're doing?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment