Skip to main content

Overview

ConnectionOptions defines how BullMQ connects to Redis. You can provide either ioredis configuration options or an existing Redis client instance.

Type Definition

Using RedisOptions

Provide ioredis configuration as an object:

Common RedisOptions Properties

host

host
string
default:"'127.0.0.1'"
Redis server hostname

port

port
number
default:"6379"
Redis server port

password

password
string
Redis server password

db

db
number
default:"0"
Redis database index

username

username
string
Redis username (for Redis 6+ ACL)

tls

tls
object
TLS/SSL configuration

maxRetriesPerRequest

maxRetriesPerRequest
number | null
Maximum retry attempts per request. Must be null for Workers

retryStrategy

retryStrategy
function
Function to determine retry delay

Examples

Basic Connection

With Authentication

With Redis 6 ACL

With TLS

With Custom Retry Strategy

Using Redis URL

Using Existing Redis Client

You can pass an existing ioredis client instance:

Redis Cluster

For Redis Cluster, create an ioredis Cluster instance:

Redis Sentinel

For Redis Sentinel:

Important Notes

maxRetriesPerRequest for Workers

Workers require maxRetriesPerRequest: null because they use blocking operations:
BullMQ automatically sets this when you provide connection options directly.

Connection Sharing

Multiple BullMQ instances can share the same connection:

Closing Shared Connections

When sharing connections, close the connection manually after closing all instances:

Environment Variables

You can use environment variables for connection configuration: