bullmq - v6.4.0
    Preparing search index...

    Class RedisRelayBackend

    Redis implementation of IRelayBackend. Every operation is one of the relay* Lua scripts; this class only passes arguments and decodes results.

    Keys of a namespace live under {prefix}::relay:{<namespace>}:

    • The empty segment after the prefix keeps the relay out of the queues' keyspace: every queue key (jobs included) is {prefix}:{queue}:... with a non-empty queue name, so no queue (not even one named "relay") nor any of its jobs can ever collide with a relay key.
    • Every key ends with a fixed word that is not a queue key suffix, never with a node id or topic, so tools that discover queues by key suffix (*:*:id, *:*:meta) never mistake relay keys for queues.
    • The namespace is a hash tag, so on Redis Cluster each namespace is one slot (the unit of scale) whatever the prefix.
    Key Type Content
    :layout hash layout version
    :nodes sorted set node → lease deadline
    :started sorted set node → registration time
    :{id}:node hash info, hb, backlog, dropped; expires with the lease
    :{id}:inbox stream the node's messages; expires with the lease
    :subs sorted set subscription index (see includes/relayIndex.lua)
    :cleanup sorted set removed nodes whose subscriptions are being pruned
    :retained sorted set topic → expiry
    :{topic}:ret hash retained message (m, ts, d)
    :mid string message id counter (starts at the server time in µs)

    Every key expires on its own when the namespace has no live node (and no retained message), so nothing is left behind even if no node sweeps it. {prefix}::relay:namespaces (sorted set: namespace → in use until) lists the namespaces in use, and expires on its own as well.

    Each node's inbox is a stream, read with a blocking XREAD on a dedicated connection. Entries published while that connection is reconnecting are read once it's back.

    Hierarchy

    • EventEmitter
      • RedisRelayBackend

    Implements

    Index
    initialInboxCursor: "0-0" = '0-0'

    Position from which a freshly registered node reads its inbox.

    namespace: string
    • Experimental

      Read-only getters, for dashboards. Lists are paginated like the queue getters: start and end are inclusive positions (from 0), and an end of -1 means "to the end". Orders are stable: nodes by registration, subscriptions and patterns by value (bytewise), retained messages by expiry.

      Returns Promise<RelayCounts>

    • Experimental

      Renews a node's lease.

      Parameters

      • nodeId: string
      • leaseMs: number

      Returns Promise<boolean>

      false when the node is not registered or its lease expired, even if it was not swept. The caller must register again and restore its subscriptions.

    • Experimental

      Returns the next entries of a node's inbox, waiting up to blockMs when there are none (0: return immediately).

      Parameters

      • nodeId: string
      • cursor: string
      • opts: { blockMs: number; count: number }

      Returns Promise<RelayInboxBatch>

    • Experimental

      Registers (or refreshes) a node, its liveness lease and its info.

      Parameters

      • nodeId: string
      • leaseMs: number
      • info: RelayNodeInfo = {}
      • inboxMaxLength: number = ...

      Returns Promise<void>

    • Experimental

      Removes up to limit nodes whose lease expired, with their subscriptions and inboxes.

      Parameters

      • limit: number

      Returns Promise<string[]>

      the ids of the removed nodes.

    • Experimental

      Removes the entries of a node's inbox that were already consumed (up to cursor, as returned by readInbox) and the oldest entries beyond maxLength.

      Parameters

      • nodeId: string
      • cursor: string
      • maxLength: number

      Returns Promise<number>

      the number of entries left: the messages the node hasn't read yet (its backlog).