0

i am trying to deploy my app on heroku.i added redistogo addon in my app.it is based on node.js and express.

i write a small code

var redis = require('socket.io-redis');

var io = require('socket.io')(server);
io.adapter(redis(process.env.REDISTOGO_URL));

but on last line i am getting error:

Error: Redis connection to redistogo:6379 failed - getaddrinfo ENOTFOUND redistogo

can any one help why i am facing this error and get rid of this error.6379 is default port but my redistogo url doesn't has 6379 port no.it's port no is 10281.

Is this a bug in socket.io-redis module or i am doing something wrong ??

mathlearner
  • 7,509
  • 31
  • 126
  • 189

2 Answers2

1

If your Redis is running on port 10281 you need to set it when initializing adapter.

var io = require('socket.io')(3000); var redis = require('socket.io-redis'); io.adapter(redis({ host: process.env.REDISTOGO_URL, port: 10281 }));

Check out documentation https://github.com/automattic/socket.io-redis#adapteropts

galethil
  • 996
  • 8
  • 13
  • Hi @galethil, my REDISTOGO_URL is like redis://redistogo:XXXXXXXXX@beardfish.redistogo.com:10281/.as mentioned in documents ,i can specify one url also in documents.An example also given var adapter = adapter('localhost:6379'); but giving it a try if your solution works or not .Thnaks – mathlearner Jun 22 '15 at 09:06
0

If redis DB has a password then it's better to opt for

 var redis = require('redis').createClient;
    var adapter = require('socket.io-redis');
    var pub = redis(port, host, { auth_pass: "pwd" });
    var sub = redis(port, host, { detect_buffers: true, auth_pass: "pwd" 

});
    io.adapter(adapter({ pubClient: pub, subClient: sub }));

in case of heroku enter host as

redis://redistogo:XXXXXXXXX@beardfish.redistogo.com
and port : provided in redistogo_url

and now it's working great.

mathlearner
  • 7,509
  • 31
  • 126
  • 189
  • hello @Ritesh Mehandiratta, unfortunately this solution doesn't work for me, My code does not work either which is : var redis = require('redis').createClient; var pub = redis("10501", "redis://redistogo:****@tarpon.redistogo.com", { auth_pass: "****" }); var sub = redis("10501", "redis://redistogo:****@tarpon.redistogo.com", { detect_buffers: true, auth_pass: "****" }); io.adapter(redisSocket({ host:process.env.REDISTOGO_URL, port: 10501,pubClient: pub, subClient: sub })); – Serhan Oztekin Oct 12 '15 at 11:00