I am trying to connect to an online redis server from heroku but my connection is getting refused I am trying to connect to an online redis server from heroku but my connection is getting refused heroku heroku

I am trying to connect to an online redis server from heroku but my connection is getting refused


I realized all i needed was to send the password for authentication immediately after the redis client connects(client.auth(password). I had to settle for redislabs enterprise for my redis hosting and also had to change from ioredis package to redis package because of some strange errors. This is the code below

redis.js

import { createClient } from 'redis';const {  PASSWORD: password,  REDIS_HOST: host, // On localhost, set to 'localhost' or '127.0.0.1'  REDIS_PORT: port, // On localhost,  set to 6379} = process.env;// connect to Redis host with port and host set as environment variablesconst client = createClient(port, host, { no_ready_check: true });// If password is in environment variable, send password to the host for authenticationif (password) {  client.auth(password, (err) => {    if (err) throw err;  });}client.on('connect', () => console.log('connected to Redis'));client.on('error', (err) => {  console.log('Redis Error:', err);});export default client;

This is optional, it only shows how the connected redis client is utilized in the index file.

index.js

import session from 'express-session';import connectRedis from 'connect-redis';import client from './redis'const redisStore = connectRedis(session);app.use(session({  secret: 'IwontTell',  name: '_stackOverflow',  resave: false,  saveUninitialized: true,  cookie: { secure: false },  store: new redisStore({ client, ttl: 86400 }),}));

This works perfecly both on localhost and online. Hope this helps someone