Guest User

redisnotworking

a guest
Mar 29th, 2013
42
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var express = require('express')
  2.   , redis = require('redis')
  3.   , routes = require('./routes')
  4.   , user = require('./routes/user')
  5.   , http = require('http')
  6.   , path = require('path');
  7.  
  8. var redisStore = redis.createClient();
  9. var app = express();
  10. app.enable('trust proxy');
  11.  
  12. app.configure(function(){
  13.   app.set('port', process.env.PORT || 3000);
  14.   app.set('views', __dirname + '/views');
  15.   app.set('view engine', 'jade');
  16.   app.use(express.favicon());
  17.   app.use(express.logger('dev'));
  18.   app.use(express.bodyParser());
  19.   app.use(express.methodOverride());
  20.   app.use(express.cookieParser('your secret here'));
  21.   app.use(express.session());
  22.   app.use(app.router);
  23.   app.use(express.static(path.join(__dirname, 'public')));
  24. });
  25.  
  26. app.configure('development', function(){
  27.   app.use(express.errorHandler());
  28. });
  29.  
  30. app.use(function(req, res, next){
  31.         var ua = req.headers['user-agent'];
  32.         redisStore.zadd('online', Date.now(), ua, next);
  33. });
  34.  
  35. app.use(function(req, res, next){
  36.         var min = 60*1000;
  37.         var ago = Date.now() - min;
  38.         redisStore.zrevrangebyscore('online', '+inf', ago, function(err, users){
  39.                 if(err){
  40.                         return next(err);
  41.                 }
  42.                 req.online = users;
  43.                 next();
  44.         });
  45. });
  46.  
  47. app.get('/', function(req, res){
  48.         var usercount = req.online.length + ' users online';
  49.         res.render('index', {title: "Test Title", useron: usercount});
  50. });
  51. app.get('/users', user.list);
  52.  
  53. http.createServer(app).listen(app.get('port'), function(){
  54.   console.log("Express server listening on port " + app.get('port'));
  55. });
RAW Paste Data