node.jsherokuredisiodocs

node.js and Redis on Heroku for IODocs


I'm trying to get IODocs running on Heroku. It requires node.js and Redis. Admittedly, I'm new to all of these technologies. Nonetheless, I've managed to get it running locally. However, I receive the following error when deploying to Heroku.

2011-12-01T11:55:18+00:00 app[web.1]: Redis To Go - port: 9030 hostname: dogfish.redistogo.com
2011-12-01T11:55:18+00:00 app[web.1]: Express server listening on port 9694
2011-12-01T11:55:19+00:00 heroku[web.1]: State changed from starting to up
2011-12-01T11:55:21+00:00 app[web.1]:         ^
2011-12-01T11:55:21+00:00 app[web.1]: Error: Redis connection to localhost:6379 failed - ECONNREFUSED, Connection refused
2011-12-01T11:55:21+00:00 app[web.1]:     at Socket.<anonymous> (/app/node_modules/redis/index.js:123:28)
2011-12-01T11:55:21+00:00 app[web.1]:     at Socket.emit (events.js:64:17)
2011-12-01T11:55:21+00:00 app[web.1]:     at Array.<anonymous> (net.js:828:27)
2011-12-01T11:55:21+00:00 app[web.1]:     at EventEmitter._tickCallback (node.js:126:26)
2011-12-01T11:55:23+00:00 heroku[web.1]: State changed from up to crashed

The only time I received a similar warning on my local mating was when Redis was not running. From what I can tell the Redis add-on is enabled for my app and running:

$ heroku config --long
NODE_ENV      => production
PATH          => bin:node_modules/.bin:/usr/local/bin:/usr/bin:/bin
REDISTOGO_URL => redis://redistogo:52847221366cb677460c306e4f482c5b@dogfish.redistogo.com:9030/

I've also tried some configuration suggestions. Neither seem to work.

// redis connection in app.js
var db;
if (process.env.REDISTOGO_URL) {
   var rtg = require("url").parse(process.env.REDISTOGO_URL);
// tried this line as well... gave a different error on .connect();
// db = require('redis-url').connect(process.env.REDISTOGO_URL);
   db = redis.createClient(rtg.port, rtg.hostname);
   db.auth(rtg.auth.split(":")[1]);

   // debug
   sys.puts('Redis To Go - port: ' + rtg.port + ' hostname: ' + rtg.hostname);
} else {
   db = redis.createClient(config.redis.port, config.redis.host);
   db.auth(config.redis.password);
}

From the difference in my Redis To Go debug line and Error, I'm sure this is a configuration issue. But don't know how to fix it. Any help is greatly appreciated.


Solution

  • This indeed had to do with the configuration for Redis on Heroku. There were additional lines that required updates in I/O Docs app.js.

    In the end, I piggy-backed the global config object at the top (~ line 60) after sniffing out the production (Heroku) environment.

    if (process.env.REDISTOGOURL) {
      // use production (Heroku) redis configuration
      // overwrite config to keep it simple
      var rtg = require(‘url’).parse(process.env.REDISTOGOURL);
      config.redis.port = rtg.port;
      config.redis.host = rtg.hostname;
      config.redis.password = rtg.auth.split(“:”)[1];
    }
    

    I created a blog post for installing, configuring, and deploying I/O Docs that includes this as well as other changes that were required to run I/O Docs. I recommend you review it if you're interested in this project.

    Thanks to Jan Jongboom and Kirsten Jones for helping me get started. In addition, I believe the project has been updated on GitHub to include Heroku configuration out of the box. However, I've yet to test it.