skip to Main Content

When i try to connect my Nodsjs application to RedisCloud on Heroku I am getting the following error

Redis::CannotConnectError: Error connecting to Redis on 127.0.0.1:6379 (ECONNREFUSED)

I have even tried to directly set the redis URL and port in the code to test it out as well. But still, it tried to connect to the localhost on Heroku instead of the RedisCloud URL.

const {Queue} = require('bullmq');
const Redis = require('ioredis');

const conn = new Redis(
      'redis://rediscloud:mueSEJFadzE9eVcjFei44444RIkNO@redis-15725.c9.us-east-1-4.ec2.cloud.redislabs.com:15725'

// Redis Server Connection Configuration
console.log('n==================================================n');
console.log(conn.options, process.env.REDISCLOUD_URL);

const defaultQueue = () => {
    // Initialize queue instance, by passing the queue-name & redis connection
    const queue = new Queue('default', {conn});
    return queue;
};
module.exports = defaultQueue;

Complete Dump of the Logs https://pastebin.com/N9awJYL9

3

Answers


  1. set REDISCLOUD_URL on .env file as follows

    REDISCLOUD_URL =redis://rediscloud:password@hostname:port

    import * as Redis from ‘ioredis’;
    export const redis = new Redis(process.env.REDISCLOUD_URL);

    Login or Signup to reply.
  2. I just had a hard time trying to find out how to connect the solution below worked for me.

    Edit—-
    Although I had been passed the parameters to connect to the Redis cloud, it connected to the local Redis installed in my machine. Sorry for that!
    I will leave my answer here, just in case anyone need to connect to local Redis.

    let express = require('express');
    var redis = require('ioredis');
    
    pwd = 'your_pwd'
    url = 'rediss://host'
    port = '1234'
    redisConfig = `${url}${pwd}${port}`
    client = redis.createClient({ url: redisConfig })
    
    client.on('connect', function() {
        console.log('-->> CONNECTED');
    });
    client.on("error", function(error) {
        console.error('ERRO DO REDIS', error);
    });
    
    Login or Signup to reply.
  3. Just wanted to post my case in case someone has the same problem like me.
    In my situation I was trying to use Redis with Bull, so i need it the url/port,host data to make this happened.

    Here is the info:
    https://devcenter.heroku.com/articles/node-redis-workers

    but basically you can start your worker like this:

    let REDIS_URL = process.env.REDISCLOUD_URL || 'redis://127.0.0.1:6379';
    
    //Once you got Redis info ready, create your task queue
    const queue = new Queue('new-queue', REDIS_URL);
    

    In the case you are using local, meaning ‘redis://127.0.0.1:6379’ remember to run redis-server:
    https://redis.io/docs/getting-started/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search