mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 20:40:20 +00:00
@types/bull: add missing createClient option
This commit is contained in:
@@ -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
|
||||
|
||||
Vendored
+7
-1
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user