Home > database >  Not able to connect to heroku redis
Not able to connect to heroku redis

Time:12-29

const redis = require("redis");

let client = redis.createClient({
    host: process.env.host,
    port: process.env.port,
    password:process.env.password
});

(async () => {
    client.on('error', (err) => console.log('Redis Client Error', err));
    await client.connect();
    console.log("connected to redis")
  })();

I have added redis-heroku addon to my project, Now I am trying to access it from my code but its giving me this error: "AuthError: ERR Client sent AUTH, but no password is set".

Also when I am trying to connect from terminal, I am able to connect to it but when I type any redis command , I get this "Error: Connection reset by peer".

If I am using this on my localsystem and local redis server its working fine

it will be helpful if anyone can provide me a working code of heroku redis, I think redis has two urls: REDIS_URL, REDIS_TLS_URL. The problem might be arising because of this tls(more secure)

Kinldy help me Thanks

CodePudding user response:

Heroku redis does not expose a host, port, and password variables. Instead they expose a REDIS_URL that contains all of those things in one string.

I believe you need to call createClient like this...

createClient({
  url: process.env.REDIS_URL
});

CodePudding user response:

In node-redis v4 the host and port should be inside a socket object, not directly on the main config object (see https://github.com/redis/node-redis/blob/master/docs/client-configuration.md):

const client = redis.createClient({
    socket: {
        host: process.env.host,
        port: process.env.port
    },
    password: process.env.password
});
  • Related