bullmq - v5.77.1
    Preparing search index...

    Interface IRedisClient

    Redis client interface for BullMQ.

    Abstracts the underlying Redis client library (ioredis, node-redis, Bun built-in Redis, etc.) while keeping Redis semantics. Only the Redis commands that BullMQ actually uses are declared here.

    Method signatures use structured options objects instead of ioredis-style varargs so that every adapter (ioredis, node-redis, Bun, …) can map the call to its native API without parsing positional string tokens.

    The reference implementation for ioredis lives in src/classes/ioredis-client.ts.

    interface IRedisClient {
        isCluster: boolean;
        options: Record<string, any>;
        status: string;
        bzpopmin(
            key: string,
            timeout: number,
        ): Promise<[key: string, member: string, score: string]>;
        clientList(): Promise<string>;
        clientSetName(name: string): Promise<any>;
        connect(): Promise<void>;
        defineCommand(
            name: string,
            definition: { lua: string; numberOfKeys: number; readOnly?: boolean },
        ): void;
        del(...keys: string[]): Promise<number>;
        disconnect(reconnect?: boolean): void;
        duplicate(...args: any[]): IRedisClient;
        emit(event: string | symbol, ...args: any[]): boolean;
        get(key: string): Promise<string>;
        getMaxListeners(): number;
        hdel(key: string, ...fields: string[]): Promise<number>;
        hexists(key: string, field: string): Promise<number>;
        hget(key: string, field: string): Promise<string>;
        hgetall(key: string): Promise<Record<string, string>>;
        hmget(key: string, ...fields: string[]): Promise<string[]>;
        hset(key: string, data: Record<string, string | number>): Promise<number>;
        info(): Promise<string>;
        llen(key: string): Promise<number>;
        lpos(key: string, value: string): Promise<number>;
        lrange(key: string, start: number, end: number): Promise<string[]>;
        ltrim(key: string, start: number, end: number): Promise<string>;
        multi(): IRedisTransaction;
        nodes?(): IRedisClient[];
        off(event: string, listener: (...args: any[]) => void): this;
        on(event: string, listener: (...args: any[]) => void): this;
        once(event: string, listener: (...args: any[]) => void): this;
        pipeline(): IRedisTransaction;
        quit(): Promise<string>;
        removeAllListeners(event?: string | symbol): this;
        removeListener(event: string, listener: (...args: any[]) => void): this;
        runCommand(name: string, args: any[]): Promise<any>;
        scan(
            cursor: string | number,
            options: { COUNT?: number; MATCH?: string },
        ): Promise<[string, string[]]>;
        scanStream(options: { count?: number; match: string }): Readable;
        set(
            key: string,
            value: string | number,
            options?: { EX?: number; PX?: number },
        ): Promise<string>;
        setMaxListeners(n: number): this;
        smembers(key: string): Promise<string[]>;
        xadd(
            key: string,
            id: string,
            fields: Record<string, string | number>,
            options?: { approximate?: boolean; MAXLEN?: number },
        ): Promise<string>;
        xread(
            streams: { id: string; key: string }[],
            options?: { BLOCK?: number; COUNT?: number },
        ): Promise<any>;
        xtrim(
            key: string,
            strategy: "MAXLEN",
            threshold: number,
            options?: { approximate?: boolean },
        ): Promise<number>;
        zcard(key: string): Promise<number>;
        zrange(
            key: string,
            start: number,
            end: number,
            options?: { WITHSCORES?: boolean },
        ): Promise<string[]>;
        zrevrange(
            key: string,
            start: number,
            end: number,
            options?: { WITHSCORES?: boolean },
        ): Promise<string[]>;
        zscore(key: string, member: string): Promise<string>;
    }
    Index

    Properties

    isCluster: boolean

    Whether this client is connected to a Redis Cluster.

    options: Record<string, any>

    Client configuration options (shape is adapter-specific).

    status: string

    Current connection status. Adapters must expose at least the values 'ready', 'wait', and 'end' so that RedisConnection.waitUntilReady works correctly.

    Methods

    • Block until an element is available in the given sorted set, or the timeout expires.

      The return shape mirrors ioredis' native bzpopmin: [key, member, score] on success, or null on timeout. Adapters for other clients (node-redis, bun) MUST convert their native return value to this tuple form. This avoids mutating the shape of bzpopmin on shared ioredis instances, which would be a breaking change for code that uses the same client outside of BullMQ.

      Parameters

      • key: string
      • timeout: number

      Returns Promise<[key: string, member: string, score: string]>

    • Register a Lua script as a named command so it can later be invoked via runCommand.

      Parameters

      • name: string

        Command name that will be callable via runCommand.

      • definition: { lua: string; numberOfKeys: number; readOnly?: boolean }

        Script definition.

        • numberOfKeys – number of KEYS[] arguments the script expects.
        • lua – Lua source code.
        • readOnly – (optional) hint that the script only reads data; some adapters (e.g. ioredis) use this to route the call to a replica in read-only mode.

      Returns void

    • Parameters

      • event: string | symbol
      • ...args: any[]

      Returns boolean

    • Parameters

      • key: string
      • ...fields: string[]

      Returns Promise<number>

    • Parameters

      • key: string
      • field: string

      Returns Promise<number>

    • Parameters

      • key: string

      Returns Promise<Record<string, string>>

    • Parameters

      • key: string
      • ...fields: string[]

      Returns Promise<string[]>

    • SET one or more hash fields from a field→value map.

      Parameters

      • key: string
      • data: Record<string, string | number>

      Returns Promise<number>

    • Parameters

      • key: string
      • start: number
      • end: number

      Returns Promise<string[]>

    • Parameters

      • key: string
      • start: number
      • end: number

      Returns Promise<string>

    • Parameters

      • event: string
      • listener: (...args: any[]) => void

      Returns this

    • Parameters

      • event: string
      • listener: (...args: any[]) => void

      Returns this

    • Parameters

      • event: string
      • listener: (...args: any[]) => void

      Returns this

    • Parameters

      • event: string
      • listener: (...args: any[]) => void

      Returns this

    • Execute a previously registered Lua script command by name.

      Parameters

      • name: string

        The command name passed to defineCommand.

      • args: any[]

        Arguments forwarded to the script (KEYS first, then ARGV).

      Returns Promise<any>

      A Promise<any> whose resolved value matches the return value of the Lua script. BullMQ scripts return integers, strings, or arrays of strings/integers. Callers in Scripts.execCommand cast the result to the expected concrete type after the call.

    • Parameters

      • cursor: string | number
      • options: { COUNT?: number; MATCH?: string }

      Returns Promise<[string, string[]]>

    • Parameters

      • options: { count?: number; match: string }

      Returns Readable

    • Parameters

      • key: string
      • value: string | number
      • Optionaloptions: { EX?: number; PX?: number }

      Returns Promise<string>

    • Append an entry to a stream.

      Parameters

      • key: string

        Stream key

      • id: string

        Entry ID (typically '*' for auto-generated)

      • fields: Record<string, string | number>

        Field-value pairs for the stream entry

      • Optionaloptions: { approximate?: boolean; MAXLEN?: number }

        Optional MAXLEN trimming parameters

      Returns Promise<string>

    • Read from one or more streams.

      Parameters

      • streams: { id: string; key: string }[]

        Array of stream/id pairs to read from

      • Optionaloptions: { BLOCK?: number; COUNT?: number }

        Optional BLOCK timeout and COUNT

      Returns Promise<any>

    • Trim a stream.

      Parameters

      • key: string

        Stream key

      • strategy: "MAXLEN"

        Trim strategy (e.g. 'MAXLEN')

      • threshold: number

        Maximum stream length

      • Optionaloptions: { approximate?: boolean }

        Optional approximate trimming

      Returns Promise<number>

    • Parameters

      • key: string
      • start: number
      • end: number
      • Optionaloptions: { WITHSCORES?: boolean }

      Returns Promise<string[]>

    • Parameters

      • key: string
      • start: number
      • end: number
      • Optionaloptions: { WITHSCORES?: boolean }

      Returns Promise<string[]>

    • Parameters

      • key: string
      • member: string

      Returns Promise<string>