npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@saga-bus/transport-redis

v0.2.1

Published

Redis Streams transport for saga-bus

Readme

@saga-bus/transport-redis

Redis Streams transport for saga-bus using ioredis.

Features

  • Redis Streams - Uses XADD/XREADGROUP for reliable message delivery
  • Consumer Groups - Competing consumers with automatic load balancing
  • Message Acknowledgment - Manual XACK after successful processing
  • Delayed Messages - Sorted set-based delayed delivery (ZADD/ZRANGEBYSCORE)
  • Pending Recovery - Automatic claiming of unacknowledged messages (XCLAIM)
  • Stream Trimming - Configurable MAXLEN for memory management

Installation

npm install @saga-bus/transport-redis ioredis
# or
pnpm add @saga-bus/transport-redis ioredis

Usage

Basic Setup

import Redis from "ioredis";
import { RedisTransport } from "@saga-bus/transport-redis";

const redis = new Redis({
  host: "localhost",
  port: 6379,
});

const transport = new RedisTransport({
  redis,
  consumerGroup: "order-processor",
});

await transport.start();

With Connection Options

import { RedisTransport } from "@saga-bus/transport-redis";

const transport = new RedisTransport({
  connection: {
    host: "localhost",
    port: 6379,
    password: "secret",
    db: 0,
  },
  consumerGroup: "order-processor",
});

Publishing Messages

interface OrderCreated {
  type: "OrderCreated";
  orderId: string;
  amount: number;
}

// Immediate delivery
await transport.publish<OrderCreated>(
  { type: "OrderCreated", orderId: "123", amount: 99.99 },
  { endpoint: "orders" }
);

// With partition key (for ordering)
await transport.publish<OrderCreated>(
  { type: "OrderCreated", orderId: "123", amount: 99.99 },
  { endpoint: "orders", key: "customer-456" }
);

// Delayed delivery (5 minutes)
await transport.publish<OrderCreated>(
  { type: "OrderCreated", orderId: "123", amount: 99.99 },
  { endpoint: "orders", delayMs: 5 * 60 * 1000 }
);

Subscribing to Messages

await transport.subscribe(
  { endpoint: "orders", concurrency: 5 },
  async (envelope) => {
    console.log("Received:", envelope.type, envelope.payload);
    // Message is automatically acknowledged after successful processing
  }
);

await transport.start();

With saga-bus

import { createBus } from "@saga-bus/core";
import { RedisTransport } from "@saga-bus/transport-redis";
import Redis from "ioredis";

const bus = createBus({
  transport: new RedisTransport({
    redis: new Redis(),
    consumerGroup: "my-app",
  }),
  // ... other config
});

Configuration Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | redis | Redis | - | ioredis client instance | | connection | RedisOptions | - | Connection options (alternative to redis) | | keyPrefix | string | "saga-bus:" | Prefix for all Redis keys | | consumerGroup | string | - | Consumer group name (required for subscribing) | | consumerName | string | Auto UUID | Consumer name within the group | | autoCreateGroup | boolean | true | Create consumer groups automatically | | batchSize | number | 10 | Messages to fetch per read | | blockTimeoutMs | number | 5000 | Block timeout for XREADGROUP | | maxStreamLength | number | 0 | Max stream length (0 = unlimited) | | approximateMaxLen | boolean | true | Use approximate MAXLEN (~) | | delayedPollIntervalMs | number | 1000 | How often to check delayed messages | | delayedSetKey | string | "saga-bus:delayed" | Key for delayed messages sorted set | | pendingClaimIntervalMs | number | 30000 | How often to claim pending messages | | minIdleTimeMs | number | 60000 | Min idle time before claiming |

Redis Data Structures

Streams

Messages are stored in Redis Streams with key pattern:

{keyPrefix}stream:{endpoint}

Example: saga-bus:stream:orders

Each message contains:

data: <JSON envelope>

Delayed Messages

Delayed messages use a sorted set:

{delayedSetKey}

Score: Unix timestamp (ms) when message should be delivered Value: JSON with { streamKey, envelope, deliverAt }

Error Handling

  • Failed messages are NOT acknowledged, allowing retry via pending recovery
  • Pending messages older than minIdleTimeMs are claimed by active consumers
  • Consumer group creation ignores "BUSYGROUP" errors (already exists)

Performance Tips

  1. Batch Size: Increase batchSize for high-throughput scenarios
  2. Stream Trimming: Set maxStreamLength to prevent unbounded growth
  3. Approximate MAXLEN: Keep approximateMaxLen: true for better performance
  4. Connection Pooling: Pass a shared Redis client for connection reuse

License

MIT