简体   繁体   中英

Redis Heroku Node.JS Connection Refused

I'm working through a CodeSchool "Soup to Bits" screencast, deploying a simple node.js + redis app to Heroku, and what they've got in the screencast doesn't work for me. Simply trying to get the app to connect to redis using redistogo. Here is the code I'm using, and below the error:

// Redis connection
var redis = require('redis');
if (process.env.REDISTOGO_URL) {
    // production
    var rtg = require("url").parse(process.env.REDISTOGO_URL);
    var client = redis.createClient(rtg.port, rtg.hostname);
    client.auth(rtg.auth.split(":")[1]);
} else {
    // development
    var client = redis.createClient();
    client.select((process.env.NODE_ENV || 'development').length);
}

Error message:

2015-02-09T10:52:58.078927+00:00 heroku[web.1]: State changed from crashed to starting
2015-02-09T10:53:00.725321+00:00 heroku[web.1]: Starting process with command `./bin/www`
2015-02-09T10:53:03.121072+00:00 app[web.1]: running on port: 18964
2015-02-09T10:53:03.122834+00:00 app[web.1]: 
2015-02-09T10:53:03.123151+00:00 app[web.1]:         throw er; // Unhandled 'error' event
2015-02-09T10:53:03.125748+00:00 app[web.1]:     at net.js:441:14
2015-02-09T10:53:03.125746+00:00 app[web.1]:     at Socket.emit (events.js:95:17)
2015-02-09T10:53:03.122926+00:00 app[web.1]: events.js:72
2015-02-09T10:53:03.125737+00:00 app[web.1]: Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
2015-02-09T10:53:03.123188+00:00 app[web.1]:               ^
2015-02-09T10:53:03.125743+00:00 app[web.1]:     at RedisClient.on_error (/app/node_modules/redis/index.js:196:24)
2015-02-09T10:53:03.125745+00:00 app[web.1]:     at Socket.<anonymous> (/app/node_modules/redis/index.js:106:14)
2015-02-09T10:53:03.125749+00:00 app[web.1]:     at process._tickCallback (node.js:442:13)
2015-02-09T10:53:03.910186+00:00 heroku[web.1]: Process exited with status 8
2015-02-09T10:53:03.919708+00:00 heroku[web.1]: State changed from starting to crashed

Can anyone see what I'm missing?

Ha, well this is a first. The issue was that I had not declared a variable with Heroku – my credit card.

Needed to enter my CC to add Redis To Go module.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM