Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting to redis using kue always creates a connection to localhost

I can't connect to Redis using kue, I've followed this article, practically I'm creating the connection by using the kue redis client, and the connection code is this:

  var kue = require('kue'),
  redis = require('kue/node_modules/redis');

  app.redisClient =  redis.createClient('6379', 'remoteip',{});
  app.redisClient.on('error', function (err) {
      console.log('Redis error encountered', err);
  });

  app.redisClient.on('end', function() {
      console.log('Redis connection closed');
   });

   kue.redis.createClient = function() {
      console.log('client ------------------',app.redisClient);
      return app.redisClient;
   };

and it seems like Kue is trying to connect to a local Redis (which I don't have installed), because I'm getting this exception:

Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED

I've read this post and it seems like the issue has been resolved in version 0.8 and I'm using 0.8.11 :/, finally I also wanted to override the client using a different client instance by using redis nodejs without any luck, because I'm getting the same error.

any help will be more than appreciated. thanks!

like image 673
pedrommuller Avatar asked Nov 10 '22 19:11

pedrommuller


1 Answers

I used a different way to setup the connection and it works so far this is what I've done:

app.redisClient =  redis.createClient(config.redisPort, config.redisUrl,{});

app.redisClient.on('connect', function () {
    console.info('successful connection to redis server');
});

app.redisClient.on('error', function (err) {
    console.log('Redis error encountered', err);
});

app.redisClient.on('end', function() {
    console.log('Redis connection closed');
});

kue.app.listen(config.kuePort);

app.jobs = kue.createQueue({
    redis: {
        createClientFactory: function(){
            return app.redisClient;
        }
    }
});
like image 130
pedrommuller Avatar answered Nov 14 '22 22:11

pedrommuller