From ef948ec46c58d11fe3e4c96b721138ef066263f9 Mon Sep 17 00:00:00 2001 From: typpo Date: Fri, 6 Apr 2012 17:52:10 -0400 Subject: [PATCH] switch to redis-url --- app.js | 13 ++++++++----- package.json | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app.js b/app.js index 6932a48..fb3057d 100644 --- a/app.js +++ b/app.js @@ -1,7 +1,12 @@ var express = require('express') , app = express.createServer() , nodemailer = require('nodemailer') - , redis = require('redis') + +var redis; +if (process.env.NODE_ENV == 'production') + redis = require('redis-url').connect(process.env.REDISTOGO_URL); +else + redis = require('redis-url').connect(); // Express config app.set('views', __dirname + '/views'); @@ -30,14 +35,12 @@ app.get('/', function(req, res) { app.post('/text', function(req, res) { var keystr = req.connection.remoteAddress + '_' + dateStr(); - var rclient = redis.createClient(); - rclient.incr(keystr, function(err, num) { - rclient.quit(); - + redis.incr(keystr, function(err, num) { if (err) { res.send({success:false,msg:'Could not validate IP quota.'}); return; } + if (num < 51) { sendText(req.body.number, req.body.msg, function(err) { if (err) diff --git a/package.json b/package.json index 96759f8..f00cc69 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "express": "2.5.2" , "jade": "0.14.2" , "nodemailer": "latest" - , "redis": "latest" + , "redis-url": "latest" } , "devDependencies": { }