2

I cannot connect to Heroku Redis using TLS. I tried whats given in heroku docs and the answer on this post How to Connect Heroku Redis TLS Node? but nothing seems to work. My current redis options look like:

const Redis = require('ioredis');
const url = process.env.REDIS_URL;
const options = {
  tls: {
    rejectUnauthorized: false,
  },
};
const opts = new Redis(url, options);

Error that I am getting is

[ioredis] Unhandled error event:Error: connect ETIMEDOUT
at TLSSocket.<anonymous
(/app/node_modules/ioredis/built/redis/index.js:310:37)
 at Object.onceWrapper (events.js:421:28)
at TLSSocket.emit (events.js:315:20)
.....

Also what is the difference between REDIS_URL and REDIS_TLS_URL? Which one to use?

Prachi S
  • 21
  • 4
  • What error are you getting specifically that defines "nothing seems to work"? The error would save a lot of guesswork. – syntaqx Apr 28 '21 at 18:49
  • @syntaqx I added the error, thanks for the comment. – Prachi S Apr 28 '21 at 19:54
  • When you deployed the application, did the `REDIS_URL` get set correctly in your application configuration? Be sure the value set in your application configuration is correctly set by running: `heroku config | grep REDIS` and checking against your addon's attachment. Not trying to be a jerk here, I just know that the code you posted should work fine, so it's something else that's not quite right. – syntaqx Apr 28 '21 at 20:07
  • yea it is set correctly. When I run `heroku config | grep REDIS`, I see both `REDIS_TLS_URL` and `REDIS_URL` printed out and that is the same which is set in the config vars on heroku. – Prachi S Apr 28 '21 at 20:41
  • Alright cool - And lastly, will you make sure you're using an up-to-date version of `ioredis`? There was a large [`ETIMEDOUT` issue](https://github.com/luin/ioredis/issues/918) solved in 2019, but I knw some of the heroku demos don't update their dependencies frequently. – syntaqx Apr 28 '21 at 20:59

1 Answers1

2

REDIS_TLS_URL will have an extra 's' in the scheme of the url -> rediss://password@host:port vs. the REDIS_URL (with a single 's' in it's scheme). The other difference is the port. The TLS port is usually +1 of the regular port. On Heroku Redis version 6, you need to use the REDIS_TLS_URL along with tls option you defined above.

const Redis = require('ioredis');
const url = process.env.REDIS_TLS_URL;
const options = {
  tls: {
     rejectUnauthorized: false,
  },
};
const opts = new Redis(url, options);
elnigerian
  • 21
  • 3