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
2
Answers
Heroku redis does not expose a
host
,port
, andpassword
variables. Instead they expose aREDIS_URL
that contains all of those things in one string.I believe you need to call createClient like this…
In node-redis v4 the
host
andport
should be inside asocket
object, not directly on the main config object (see https://github.com/redis/node-redis/blob/master/docs/client-configuration.md):