kue icon indicating copy to clipboard operation
kue copied to clipboard

A process cannot open multiple redis instances?

Open jingzhiMo opened this issue 8 years ago • 9 comments

Hi, I want to create two queue in my process.But only the first queue created is useful.0

    var kue = require('kue');
    var queue2 = kue.createQueue({
        redis: {
            post: 6379,
            host: "127.0.0.1",
            db: 2,
        }
    });
    var queue3 = kue.createQueue({
        redis: {
           post: 6379,
           host: "127.0.0.1",
           db: 3,
        }
    });
    // create job
    queue2.create('test2', {x: 2}).save()
    queue3.create('test3', {x: 3}).save()

when I check the queue, the queue2 has two job. queue3 has none job; How can I create multiple queue in one process? Thanks.

jingzhiMo avatar Jun 02 '16 03:06 jingzhiMo

In each process you can setup on a single redis configuration since Queue is singleton.

var kue = require('kue');
    var queue = kue.createQueue({
        redis: {
            post: 6379,
            host: "127.0.0.1",
            db: 2,
        }
    });
    // create job
    queue.create('test2', {x: 2}).save()
    queue.create('test3', {x: 3}).save()

If you want to create test2 & test3 on separate redis DB's you should use different node.js processes currently.

Kue 1.0 will change this :)

behrad avatar Jun 02 '16 05:06 behrad

I have a question in the same vein - given that you set the redis connection in createQueue, how can I be sure the right redis connection is being used if I don't have a queue object and am just doing some simple maintenance with the kue object? (kue.Job.rangeByState)

mz3 avatar Jun 02 '16 22:06 mz3

@mz3 I'm not sure if I got your point! Kue is using a single connection for static methods like rangeByState

behrad avatar Jun 03 '16 00:06 behrad

My question is given this small sample script, where would one specify the redis connection?

const kue = require('kue');
kue.Job.get(1, (err, job) => {
  console.log('removed job #1');
});

mz3 avatar Jun 03 '16 16:06 mz3

Currently you should initialize a Queue with kue.createQueue and send redis options before calling kue.Job.get, and Yes! this is an issue with current design. I'm creating an issue for this to be handled in Kue 1.0

behrad avatar Jun 03 '16 17:06 behrad

Alright - that makes sense. Thanks so much for clarifying. Can't wait to see kue 1.0!

mz3 avatar Jun 03 '16 17:06 mz3

hi, maybe this code help you multi-redis-kue

i change many file to access multi redis db (this work so good but maybe have bug)

poyaz avatar Dec 27 '16 09:12 poyaz

Hi,

I just came across this issue. When can we expect the new release with the fix? :open_mouth:

utsavkesharwani avatar Mar 20 '18 12:03 utsavkesharwani

+1 to this. Tried it today without thinking and was confused when the second queue job appeared in the first queue.

Seems the only "fix"/solution right now is to JSON API post to the second queue? (Which works for queue create which is fine for me)

But, yeah, gonna need separate processes if you wanna consume two queues. (Which matches my setup anyway)

BarryCarlyon avatar Apr 03 '18 13:04 BarryCarlyon