How can I connect redis cloud instance to bull queue?

1.9k Views Asked by At

I am trying to connect redis free cloud instance with bull queue but getting error as it is not able to connect.

  1. I tried below code:
const Bull = require("bull");
const emailQueue = new Bull("email", {
  redis: "",
});

For above code it is giving error Error: connect ECONNREFUSED 127.0.0.1:6379 message.

  1. Also tried something like this: using tls field but did not work.
const Bull = require("bull");
const emailQueue = new Bull("email", {
   redis: {
     port: "",
     host: "",
     tls: { rejectUnauthorized: false },
   },
});

Note: I am using redis free cloud instance with bull queue and also download redis insight desktop application. I have added database to redis insight desktop app and it is connected but in node application it is not working. Am I missing any config?

1

There are 1 best solutions below

2
On

Firstly, you have to ensure that your redis server is running locally since you want to connect to 127.0.0.1:6379.

Secondly, to get the connection error you might be having, you can try this:

emailQueue.on('error', (error) => {
    console.log(error);
})

For me, I had no issue connecting to my local Redis server but I could not connect to remote Redis servers especially Redis labs and AWS ElasticCache. From the error message, I realized that I needed extra authentication and I just provided the host, port, username, and password for Redis Labs while I only needed to provide a host, port, and password for AWS ElasticCache, leaving the username as an empty string in my env.

const {
    REDIS_HOST,
    REDIS_PORT,
    REDIS_USERNAME,
    REDIS_PASSWORD,
} = process.env

const emailQueue = new Queue('email', {
    redis: {
      port: REDIS_PORT, 
      host: REDIS_HOST,
      username: REDIS_USERNAME,
      password: REDIS_PASSWORD
    }
});