Skip to main content

Overview

Every BullMQ class (Queue, Worker, QueueEvents) requires a connection to Redis. BullMQ uses ioredis under the hood, and connection options are passed directly to the ioredis constructor.
If no connection options are provided, BullMQ defaults to localhost:6379.

Connection Options

BullMQ accepts connection configuration through the ConnectionOptions interface:

Basic Connection

Reusing Connections

You can share an existing ioredis instance across multiple Queue instances to reduce connection overhead:
Workers and QueueEvents create additional blocking connections internally, even when reusing connections.

Connection Behavior

Queue vs Worker Connections

The connection requirements differ between producers and consumers:
Use Case: Adding jobs via HTTP endpoints or API calls
For producers, use the default maxRetriesPerRequest setting so operations fail quickly if Redis is unavailable.

Important Configuration

maxRetriesPerRequest

This setting controls how many times ioredis retries a failed command:
  • null (recommended for Workers): Retry indefinitely
  • Number (recommended for Queues): Retry N times before throwing an error
BullMQ will throw an exception if maxRetriesPerRequest is not null when passing a manual Redis client to Worker instances.

Redis Server Configuration

Ensure your Redis instance has the following setting:
This prevents automatic key eviction which would cause unexpected errors in BullMQ.

Key Prefix

Do not use ioredis’s keyPrefix option. It is incompatible with BullMQ.Instead, use BullMQ’s built-in prefix option:

Advanced Connection Options

Retry Strategy

Customize the retry backoff behavior:

Redis Cluster

Connect to a Redis cluster:

Connection Lifecycle

The RedisConnection class manages connection state:

Waiting for Ready

All BullMQ classes expose a waitUntilReady() method:

Closing Connections

Always close connections gracefully:

Version Requirements

  • Minimum Redis Version: 5.0.0
  • Recommended Redis Version: 6.2.0 or higher
BullMQ supports alternative Redis implementations:
  • Dragonfly: Full support
  • Valkey: Full support

Connection Events

Listen to connection events:

Best Practices

Use Connection Pooling

Reuse connections when possible to reduce overhead, but create separate connections for blocking operations.

Set maxRetriesPerRequest

Use null for workers (background) and a number for queues (foreground).

Configure Redis Properly

Set maxmemory-policy=noeviction and ensure sufficient memory.

Monitor Connections

Track connection health and implement proper error handling.

Next Steps

Queues

Learn how to create and manage queues

Workers

Process jobs with workers