mirror of
https://github.com/OptimalBits/bull.git
synced 2026-07-02 08:27:43 +08:00
Merge branch 'custom-client' of https://github.com/rossimo/bull into rossimo-custom-client
This commit is contained in:
+11
-3
@@ -60,6 +60,14 @@ var Queue = function Queue(name, redisPort, redisHost, redisOptions){
|
||||
redisDB = redisOpts.DB || redisDB;
|
||||
}
|
||||
|
||||
function createClient() {
|
||||
if(redisOptions !== undefined && redisOptions.createClient !== undefined){
|
||||
return redisOptions.createClient();
|
||||
}else{
|
||||
return redis.createClient(redisPort, redisHost, redisOptions);
|
||||
}
|
||||
}
|
||||
|
||||
redisPort = redisPort || 6379;
|
||||
redisHost = redisHost || '127.0.0.1';
|
||||
|
||||
@@ -70,7 +78,7 @@ var Queue = function Queue(name, redisPort, redisHost, redisOptions){
|
||||
//
|
||||
// Create queue client (used to add jobs, pause queues, etc);
|
||||
//
|
||||
this.client = redis.createClient(redisPort, redisHost, redisOptions);
|
||||
this.client = createClient();
|
||||
|
||||
getRedisVersion(this.client).then(function(version){
|
||||
if(semver.lt(version, MINIMUM_REDIS_VERSION)){
|
||||
@@ -83,12 +91,12 @@ var Queue = function Queue(name, redisPort, redisHost, redisOptions){
|
||||
//
|
||||
// Create blocking client (used to wait for jobs)
|
||||
//
|
||||
this.bclient = redis.createClient(redisPort, redisHost, redisOptions);
|
||||
this.bclient = createClient();
|
||||
|
||||
//
|
||||
// Create event subscriber client (receive messages from other instance of the queue)
|
||||
//
|
||||
this.eclient = redis.createClient(redisPort, redisHost, redisOptions);
|
||||
this.eclient = createClient();
|
||||
|
||||
this.delayTimer = null;
|
||||
this.processing = 0;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/*global */
|
||||
"use strict";
|
||||
|
||||
var Job = require('../lib/job');
|
||||
@@ -32,6 +33,15 @@ describe('Priority queue', function(){
|
||||
sandbox.restore();
|
||||
});
|
||||
|
||||
it('allow custom clients', function(){
|
||||
var clients = 0;
|
||||
queue = new Queue(STD_QUEUE_NAME, {redis: {opts: {createClient: function(){
|
||||
clients++;
|
||||
return redis.createClient();
|
||||
}}}});
|
||||
expect(clients).to.be(15);
|
||||
});
|
||||
|
||||
describe('.close', function () {
|
||||
var testQueue;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user