Kue worker with with createClientFactory: only subscriber commands may be used

558 Views Asked by At

I'm working to get my kue workers set up and have discovered something strange. If I create my queue using the default kue redis connection everything works perfectly:

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

var q = kue.createQueue();

q.process('cypher', function(job, done){});

The worker starts up perfectly. However, if I try to override the default redis connection with one of my own I get a

Error: Connection in subscriber mode, only subscriber commands may be used

when execution hits the q.process function below:

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


var redisClient =   redis.createClient();

var q = kue.createQueue({
    redis: {
        createClientFactory: function(){

            return redisClient;
        }
    }
});

q.process('cypher', function(job, done){});

It doesn't seem to any sense. I thought maybe I was committing a classic async error, but even the following was I get the same error. Any insights?

redisClient.on('connect', function () {
    console.log('gotten here!!!');
    var q = kue.createQueue({
        redis: {
            createClientFactory: function(){

                return redisClient;
            }
        }
    });

    q.process('cypher', function(job, done){});
});
1

There are 1 best solutions below

1
On BEST ANSWER

you are not actually passing a new client each time when your factory method is called. Returning a singleton instance from createClientFactory makes kue to use the same connection for commands and pub/sub and this is not possible in redis connection modes