You can use BullMQ and Bull with Upstash Redis. BullMQ is a Node.js queue library that is built on top of Bull. It is a Redis-based queue library so you can use Upstash Redis as its storage.

Install

npm install bullmq upstash-redis

Usage

import { Queue } from 'bullmq';

const myQueue = new Queue('foo', { connection: {
        host: "UPSTASH_REDIS_ENDPOINT",
        port: 6379,
        password: "UPSTASH_REDIS_PASSWORD",
        tls: {}
    }});

async function addJobs() {
    await myQueue.add('myJobName', { foo: 'bar' });
    await myQueue.add('myJobName', { qux: 'baz' });
}

await addJobs();

Billing Optimization

BullMQ accesses Redis regularly, even when there is no queue activity. This incurs extra costs because Upstash charges per request. After receiving complaints from BullMQ users, we revised our billing algorithm. We have decided to charge only for script calls instead of all requests. This special pricing is for BullMQ users. If you use BullMQ with Upstash Redis, you will only be charged for script calls, not regular requests. This will significantly reduce your costs.

Once your billing is in optimized mode, you will see a leaf icon in the console.