# RedisQueue class · @imqueue/core

Source: https://imqueue.org/api/core/latest/core.redisqueue/
Published: 2026-08-04
Author: @imqueue maintainers (https://github.com/imqueue)
Package: @imqueue/core 3.3.2 — generated reference, not hand-written

Redis-backed message queue with at-least-once delivery — the default [IMessageQueue](https://imqueue.org/api/core/latest/core.imessagequeue/) implementation, and what [IMQ.create()](https://imqueue.org/api/core/latest/core.imq.create/) returns for a single-server configuration.

**Signature:**

```typescript
export declare class RedisQueue extends EventEmitter<EventMap> implements IMessageQueue 
```
**Extends:** EventEmitter<[EventMap](https://imqueue.org/api/core/latest/core.eventmap/)>

**Implements:** [IMessageQueue](https://imqueue.org/api/core/latest/core.imessagequeue/)

## Remarks

Connection model: the reader is per instance and exists only in [IMQMode.BOTH](https://imqueue.org/api/core/latest/core.imqmode/) or [IMQMode.WORKER](https://imqueue.org/api/core/latest/core.imqmode/) mode, while the writer and watcher connections are shared per `host:port` across every queue in the process and reference-counted. Exactly one queue per key prefix is elected as the watcher through a `<prefix>:watch:lock` key, and that owner also releases delayed messages, recovers abandoned safe-delivery hand-offs and — when [IMQOptions.cleanup](https://imqueue.org/api/core/latest/core.imqoptions.cleanup/) is on — prunes orphaned keys.

Lifecycle: [RedisQueue.start()](https://imqueue.org/api/core/latest/core.redisqueue.start/) is required before consuming or publishing, while [RedisQueue.send()](https://imqueue.org/api/core/latest/core.redisqueue.send/) starts the queue lazily. [RedisQueue.stop()](https://imqueue.org/api/core/latest/core.redisqueue.stop/) only stops consuming; use [RedisQueue.destroy()](https://imqueue.org/api/core/latest/core.redisqueue.destroy/) to release the watcher lock, the timers and the connections.

Reconnection is handled by the queue itself — ioredis's own retry strategy is disabled in favour of a capped exponential backoff from 1 s to 30 s per channel.

Events (typed by [EventMap](https://imqueue.org/api/core/latest/core.eventmap/)): `message`, with the payload, the message id and the sending queue's name; and `error`, with the error and the name of the internal routine that caught it (`OnMessage`, `OnProcessDelayed`, `OnSafeDelivery`, `OnWatch`, `OnConfig`, `OnScriptLoad`, `OnReadUnsafe` or `OnReadSafe`). Background errors are emitted only when at least one `error` listener is attached — otherwise they are logged and swallowed, so attach one if you need to observe them.

## Constructors


| Constructor | Modifiers | Description |
| --- | --- | --- |
| [(constructor)(name, options, mode)](https://imqueue.org/api/core/latest/core.redisqueue._constructor_/) |  | Creates a queue handle. No connection is opened here — call [RedisQueue.start()](https://imqueue.org/api/core/latest/core.redisqueue.start/), or [RedisQueue.send()](https://imqueue.org/api/core/latest/core.redisqueue.send/), which starts the queue implicitly. |


## Properties


| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [available](https://imqueue.org/api/core/latest/core.redisqueue.available/) | `readonly` | boolean | Returns false only when this queue is known to be unable to accept writes right now — i.e., it has a writer connection currently in a non-ready (reconnecting/closed) state. A queue that has not yet connected is considered available, since sending connects it lazily. Used for health-aware routing in the clustered queue. |
| [name](https://imqueue.org/api/core/latest/core.redisqueue.name/) |  | string | The queue name. The underlying redis list key is `<prefix>:<name>`, the same name is the default pub/sub channel used by [RedisQueue.publish()](https://imqueue.org/api/core/latest/core.redisqueue.publish/), and it is the `from` value carried by messages this queue sends. |
| [options](https://imqueue.org/api/core/latest/core.redisqueue.options/) |  | [IMQOptions](https://imqueue.org/api/core/latest/core.imqoptions/) | The effective options for this queue: [DEFAULT\_IMQ\_OPTIONS](https://imqueue.org/api/core/latest/core.default_imq_options/) merged with the values passed to the constructor. |
| [redisKey](https://imqueue.org/api/core/latest/core.redisqueue.rediskey/) | `readonly` | string | The `host:port` address of the redis server this queue talks to. |


## Methods


| Method | Modifiers | Description |
| --- | --- | --- |
| [clear()](https://imqueue.org/api/core/latest/core.redisqueue.clear/) |  | Deletes this queue's message list and its delayed-message set from redis. |
| [destroy(clearData)](https://imqueue.org/api/core/latest/core.redisqueue.destroy/) |  | Gracefully destroys this queue handle. Does not remove queue data from redis unless clearData is explicitly set to true, so that destroying one handle (e.g., on scale-down) never wipes messages still pending for other producers/consumers. |
| [isPublisher()](https://imqueue.org/api/core/latest/core.redisqueue.ispublisher/) |  | Returns true if publisher mode is enabled on this queue, false otherwise. |
| [isWorker()](https://imqueue.org/api/core/latest/core.redisqueue.isworker/) |  | Returns true if worker mode is enabled on this queue, false otherwise. |
| [publish(data, toName)](https://imqueue.org/api/core/latest/core.redisqueue.publish/) |  | Publishes a message to this queue subscription channel for currently subscribed clients. If toName specified will publish to PubSub with a different name. This can be used to implement broadcasting some messages to other subscribers on other PubSub channels. |
| [queueLength()](https://imqueue.org/api/core/latest/core.redisqueue.queuelength/) |  | Returns the number of messages currently waiting in this queue's main list. |
| [send(toQueue, message, delay, errorHandler)](https://imqueue.org/api/core/latest/core.redisqueue.send/) |  | Sends a given message to a given queue (by name). |
| [start()](https://imqueue.org/api/core/latest/core.redisqueue.start/) |  | Initializes and starts current queue routines: opens the writer (and, in [IMQMode.BOTH](https://imqueue.org/api/core/latest/core.imqmode/) or [IMQMode.WORKER](https://imqueue.org/api/core/latest/core.imqmode/) mode, the reader), joins watcher election and starts the periodic watcher check. |
| [stop()](https://imqueue.org/api/core/latest/core.redisqueue.stop/) |  | Stops consuming messages by tearing down this instance's reader connection. |
| [subscribe(channel, handler)](https://imqueue.org/api/core/latest/core.redisqueue.subscribe/) |  | Creates a subscription channel over redis and sets up channel data read handler. The effective Redis channel is `<prefix>:<channel>`. |
| [unsubscribe()](https://imqueue.org/api/core/latest/core.redisqueue.unsubscribe/) |  | Closes the subscription connection and forgets the channel name together with every handler registered through [RedisQueue.subscribe()](https://imqueue.org/api/core/latest/core.redisqueue.subscribe/). |

