@types/bull: add missing createClient option

This commit is contained in:
marshall007
2017-06-07 16:47:13 -05:00
parent 0ccd259f04
commit e99d48a0e1
2 changed files with 30 additions and 2 deletions
+23 -1
View File
@@ -2,12 +2,12 @@
* Created by Bruno Grieder
*/
import * as Redis from "ioredis";
import * as Queue from "bull";
const videoQueue = new Queue('video transcoding', 'redis://127.0.0.1:6379');
const audioQueue = new Queue('audio transcoding', {redis: {port: 6379, host: '127.0.0.1'}}); // Specify Redis connection using object
const imageQueue = new Queue('image transcoding');
const pdfQueue = new Queue('pdf transcoding');
videoQueue.process((job, done) => {
// job.data contains the custom data passed when the job was created
@@ -67,6 +67,28 @@ videoQueue.add({video: 'http://example.com/video1.mov'});
audioQueue.add({audio: 'http://example.com/audio1.mp3'});
imageQueue.add({image: 'http://example.com/image1.tiff'});
//////////////////////////////////////////////////////////////////////////////////
//
// Re-using Redis Connections
//
//////////////////////////////////////////////////////////////////////////////////
const client = new Redis();
const subscriber = new Redis();
const pdfQueue = new Queue('pdf transcoding', {
createClient: (type: string, options: Redis.RedisOptions) => {
switch (type) {
case 'client':
return client;
case 'subscriber':
return subscriber;
default:
return new Redis(options);
}
}
});
//////////////////////////////////////////////////////////////////////////////////
//
// Using Promises
+7 -1
View File
@@ -12,7 +12,7 @@ import * as Redis from "ioredis";
* It creates a new Queue that is persisted in Redis.
* Everytime the same queue is instantiated it tries to process all the old jobs that may exist from a previous unfinished session.
*/
declare var Bull: {
declare const Bull: {
// tslint:disable:unified-signatures
(queueName: string, opts?: Bull.QueueOptions): Bull.Queue;
(queueName: string, url?: string): Bull.Queue;
@@ -28,6 +28,12 @@ declare namespace Bull {
*/
redis?: Redis.RedisOptions;
/**
* When specified, the `Queue` will use this function to create new `ioredis` client connections.
* This is useful if you want to re-use connections.
*/
createClient?(type: 'client' | 'subscriber', redisOpts?: Redis.RedisOptions): Redis.Redis;
/**
* Prefix to use for all redis keys
*/