node.jsherokuheroku-redis

How to Connect Heroku Redis TLS Node?


I dont seem to be able to connect to Heroku Redis using TLS on Node.

These docs arent really much help: https://devcenter.heroku.com/articles/securing-heroku-redis

Does anyone have a working example? Should I be using REDIS_URL or REDIS_TLS_URL?

Im using node_redis v3


Solution

  • I found the Redis 6 add-on by Heroku generated an Error: self signed certificate in certificate chain error when when connecting to REDIS_URL without any parameters with ioredis on Node. You can avoid this error by passing in TLS options with rejectUnauthorized set to false.

    The rejectUnauthorized of false allows for self-signed certificates, which would be an issue if concerned about MITM attacks. See TLS options for more background.

    This is working for me with the latest ioredis package with rediss:// and redis:// URL's...

      const REDIS_URL = process.env.REDIS_URL;
      const redis_uri = url.parse(REDIS_URL);
      const redisOptions = REDIS_URL.includes("rediss://")
        ? {
            port: Number(redis_uri.port),
            host: redis_uri.hostname,
            password: redis_uri.auth.split(":")[1],
            db: 0,
            tls: {
              rejectUnauthorized: false,
            },
          }
        : REDIS_URL;
      const redis = new Redis(redisOptions);