6 javascript redis typescript nestjs
是否可以在不使用 Redis 的情况下使用 Bull(用于作业管理)?
我的代码:
@Injectable()
export class MailService {
private queue: Bull.Queue;
private readonly queueName = 'mail';
constructor() {
this.queue = new Bull(this.queueName)
}
addTaskToQueue() {
this.queue.process('send_mail',
async (job: Bull.Job, done: Bull.DoneCallback) => {
console.log('Send mail!');
console.log(JSON.stringify(job.data));
done();
})
}
async send(year: number, month: number) {
try{
await this.queue.add('send_mail', {
year,
month
});
console.log('done');
} catch(err){
console.log(err);
}
}
}
Run Code Online (Sandbox Code Playgroud)
运行后,我的控制台出现此错误:
{ Error: connect ECONNREFUSED 127.0.0.1:6379
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1107:14)
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 6379 }
Run Code Online (Sandbox Code Playgroud)
Bull 构建在 Redis 之上,这是它的后端。没有 Redis 就无法使用它。您可能可以使用 RxJS 和一些状态管理来实现某种不需要 Redis 之类的自定义系统,但 Bull 必须有 Redis。
| 归档时间: |
|
| 查看次数: |
5024 次 |
| 最近记录: |