BullMQ.Keys (BullMQ v1.0.1)

View Source

Redis key generation for BullMQ queues.

This module generates consistent Redis keys following the BullMQ naming convention. All keys follow the pattern: {prefix}:{queue_name}:{key_type}.

The default prefix is "bull" for compatibility with the Node.js BullMQ library.

Summary

Types

Queue key context containing prefix and name

Functions

Key for the active jobs list

Returns all queue-level keys for obliteration/cleanup.

Returns the base key for a queue.

Key for the completed jobs sorted set

Creates a new queue context for key generation.

Key for deduplication

Key for the delayed jobs sorted set

Key for a job's dependencies set (child jobs)

Key for the events stream

Key for the failed jobs sorted set

Get a key by name (dynamic key lookup)

Key for the job ID counter

Key for a specific job hash

Key for a job's dependencies set (alias)

Key for a job's failed children hash

Key for a job's lock (alias for lock/2)

Key for a job's logs list (alias for logs/2)

Key for a job's processed children hash (alias)

Key for the job schedulers

Key for a job's unsuccessful children sorted set

Returns the base key for a queue (without suffix).

Returns the key prefix for building job keys (with trailing colon).

Key for the rate limiter

Key for a job's lock

Key for a job's logs list

Key for the marker sorted set (for blocking operations)

Key for the queue metadata hash

Key for the metrics hash

Creates a new queue context for key generation.

Parses a job key to extract the job ID.

Extracts queue name and job ID from a full job key.

Key for the paused jobs list

Key for the priority counter

Key for the prioritized jobs sorted set

Key for a job's processed children hash

Key for the repeatable jobs hash

Returns all keys matching the queue pattern for scanning.

Key for the job schedulers (short form)

Key for the stalled jobs set

Key for the stalled check marker

Key for the waiting jobs list

Key for the waiting-children jobs sorted set

Types

queue_context()

@type queue_context() :: %{prefix: String.t(), name: String.t()}

Queue key context containing prefix and name

Functions

active(ctx)

@spec active(queue_context()) :: String.t()

Key for the active jobs list

all_queue_keys(ctx)

@spec all_queue_keys(queue_context()) :: [String.t()]

Returns all queue-level keys for obliteration/cleanup.

base(map)

@spec base(queue_context()) :: String.t()

Returns the base key for a queue.

Examples

iex> ctx = BullMQ.Keys.new("my_queue")
iex> BullMQ.Keys.base(ctx)
"bull:my_queue"

completed(ctx)

@spec completed(queue_context()) :: String.t()

Key for the completed jobs sorted set

context(name)

@spec context(String.t()) :: queue_context()

context(prefix, name)

@spec context(String.t(), String.t()) :: queue_context()

Creates a new queue context for key generation.

Examples

iex> BullMQ.Keys.context("bull", "my_queue")
%{prefix: "bull", name: "my_queue"}

iex> BullMQ.Keys.context("my_queue")
%{prefix: "bull", name: "my_queue"}

dedup(ctx, dedup_id)

@spec dedup(queue_context(), String.t()) :: String.t()

Key for deduplication

delayed(ctx)

@spec delayed(queue_context()) :: String.t()

Key for the delayed jobs sorted set

dependencies(ctx, job_id)

@spec dependencies(queue_context(), String.t()) :: String.t()

Key for a job's dependencies set (child jobs)

events(ctx)

@spec events(queue_context()) :: String.t()

Key for the events stream

failed(ctx)

@spec failed(queue_context()) :: String.t()

Key for the failed jobs sorted set

get(ctx, key)

@spec get(queue_context(), String.t()) :: String.t()

Get a key by name (dynamic key lookup)

id(ctx)

@spec id(queue_context()) :: String.t()

Key for the job ID counter

job(ctx, job_id)

@spec job(queue_context(), String.t()) :: String.t()

Key for a specific job hash

job_dependencies(ctx, job_id)

@spec job_dependencies(queue_context(), String.t()) :: String.t()

Key for a job's dependencies set (alias)

job_failed(ctx, job_id)

@spec job_failed(queue_context(), String.t()) :: String.t()

Key for a job's failed children hash

job_lock(ctx, job_id)

@spec job_lock(queue_context(), String.t()) :: String.t()

Key for a job's lock (alias for lock/2)

job_logs(ctx, job_id)

@spec job_logs(queue_context(), String.t()) :: String.t()

Key for a job's logs list (alias for logs/2)

job_processed(ctx, job_id)

@spec job_processed(queue_context(), String.t()) :: String.t()

Key for a job's processed children hash (alias)

job_scheduler(ctx)

@spec job_scheduler(queue_context()) :: String.t()

Key for the job schedulers

job_unsuccessful(ctx, job_id)

@spec job_unsuccessful(queue_context(), String.t()) :: String.t()

Key for a job's unsuccessful children sorted set

key(map)

@spec key(queue_context()) :: String.t()

Returns the base key for a queue (without suffix).

Examples

iex> ctx = BullMQ.Keys.new("my_queue")
iex> BullMQ.Keys.key(ctx)
"bull:my_queue"

key_prefix(map)

@spec key_prefix(queue_context()) :: String.t()

Returns the key prefix for building job keys (with trailing colon).

This matches the Node.js queueKeys[''] which is used to build job keys by concatenating with the job ID: prefix:queuename:jobid

Examples

iex> ctx = BullMQ.Keys.new("my_queue")
iex> BullMQ.Keys.key_prefix(ctx)
"bull:my_queue:"

limiter(ctx)

@spec limiter(queue_context()) :: String.t()

Key for the rate limiter

lock(ctx, job_id)

@spec lock(queue_context(), String.t()) :: String.t()

Key for a job's lock

logs(ctx, job_id)

@spec logs(queue_context(), String.t()) :: String.t()

Key for a job's logs list

marker(ctx)

@spec marker(queue_context()) :: String.t()

Key for the marker sorted set (for blocking operations)

meta(ctx)

@spec meta(queue_context()) :: String.t()

Key for the queue metadata hash

metrics(ctx, type)

@spec metrics(queue_context(), String.t() | :completed | :failed) :: String.t()

Key for the metrics hash

new(name, opts \\ [])

@spec new(
  String.t(),
  keyword()
) :: queue_context()

Creates a new queue context for key generation.

Alias for context/1 and context/2 with keyword options.

Examples

iex> BullMQ.Keys.new("my_queue")
%{prefix: "bull", name: "my_queue"}

iex> BullMQ.Keys.new("my_queue", prefix: "myapp")
%{prefix: "myapp", name: "my_queue"}

parse_job_id(key)

@spec parse_job_id(String.t()) :: String.t()

Parses a job key to extract the job ID.

Examples

iex> BullMQ.Keys.parse_job_id("bull:my_queue:123")
"123"

parse_job_key(key)

@spec parse_job_key(String.t()) :: {:ok, map()} | {:error, :invalid_key}

Extracts queue name and job ID from a full job key.

Examples

iex> BullMQ.Keys.parse_job_key("bull:my_queue:123")
{:ok, %{prefix: "bull", queue: "my_queue", job_id: "123"}}

paused(ctx)

@spec paused(queue_context()) :: String.t()

Key for the paused jobs list

pc(ctx)

@spec pc(queue_context()) :: String.t()

Key for the priority counter

prioritized(ctx)

@spec prioritized(queue_context()) :: String.t()

Key for the prioritized jobs sorted set

processed(ctx, job_id)

@spec processed(queue_context(), String.t()) :: String.t()

Key for a job's processed children hash

repeat(ctx)

@spec repeat(queue_context()) :: String.t()

Key for the repeatable jobs hash

scan_pattern(ctx)

@spec scan_pattern(queue_context()) :: String.t()

Returns all keys matching the queue pattern for scanning.

schedulers(ctx)

@spec schedulers(queue_context()) :: String.t()

Key for the job schedulers (short form)

stalled(ctx)

@spec stalled(queue_context()) :: String.t()

Key for the stalled jobs set

stalled_check(ctx)

@spec stalled_check(queue_context()) :: String.t()

Key for the stalled check marker

wait(ctx)

@spec wait(queue_context()) :: String.t()

Key for the waiting jobs list

waiting_children(ctx)

@spec waiting_children(queue_context()) :: String.t()

Key for the waiting-children jobs sorted set