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 🙏

© 2026 – Pkg Stats / Ryan Hefner

redis-messaging

v0.1.0

Published

Redis Messaging

Readme

redis-messaging

A lightweight, type-safe Redis Pub/Sub library for Node.js and TypeScript.

redis-messaging provides a simple abstraction over Redis Pub/Sub with a consistent API for publishing and subscribing to messages. It supports both simple payloads and structured messages with headers, making it suitable for event-driven applications, microservices, notifications, and lightweight messaging.

Examples:

redis-messaging: An example for a message processing pipeline with redis:

  • Message transport
  • Message processing
  • Validation
  • Retry
  • Persistence

Features

  • Lightweight wrapper around the official redis client
  • Type-safe APIs
  • Simple Publisher/Subscriber
  • Structured Publisher/Subscriber with message headers
  • Generic message types
  • Pluggable serialization/deserialization
  • Built-in Redis health checker
  • Minimal dependencies
  • Promise-based API
  • Enterprise-friendly design

Installation

npm install redis redis-messaging

Quick Start

Connect to Redis

import { createClient } from "redis";

const client = createClient({
  url: "redis://localhost:6379",
});

await client.connect();

Simple Publisher

Publish plain objects without headers.

import { Publisher } from "redis-messaging";

interface UserCreated {
  id: string;
  name: string;
}

const publisher = new Publisher<UserCreated>(
  client,
  "users.created"
);

await publisher.publish({
  id: "1001",
  name: "John"
});

Simple Subscriber

import { Subscriber } from "redis-messaging";

interface UserCreated {
  id: string;
  name: string;
}

const subscriber = new Subscriber<UserCreated, void>(
  client,
  "users.created",
  console.error
);

await subscriber.subscribe(async (user) => {
  console.log(user.id);
  console.log(user.name);
});

Publisher with Headers

When additional metadata is required, use RedisPublisher.

import { RedisPublisher } from "redis-messaging";

const publisher = new RedisPublisher<UserCreated>(
  client,
  "users.created"
);

await publisher.publish(
  {
    id: "1001",
    name: "John"
  },
  {
    correlationId: "abc-123",
    source: "user-service"
  }
);

Subscriber with Headers

import { RedisSubscriber } from "redis-messaging";

const subscriber = new RedisSubscriber<UserCreated, void>(
  client,
  "users.created",
  console.log
);

await subscriber.subscribe(async (user, headers) => {

  console.log(user);

  console.log(headers?.correlationId);

  console.log(headers?.source);

});

Custom Serializer

You can replace the default JSON serializer.

const publisher = new Publisher<MyData>(
    client,
    "events",
    serialize
);

Example

function serialize(data: MyData): string {
    return JSON.stringify(data);
}

Custom Deserializer

const subscriber = new Subscriber<MyData, void>(
    client,
    "events",
    console.error,
    deserialize
);
function deserialize(message: string): MyData {
    return JSON.parse(message);
}

Message Format

RedisPublisher automatically wraps data into the following structure.

{
    data: T,
    headers?: {
        [key: string]: string
    }
}

Example

{
  "data": {
    "id": "1001",
    "name": "John"
  },
  "headers": {
    "correlationId": "abc-123",
    "source": "user-service"
  }
}

Health Check

RedisChecker provides a lightweight health check implementation suitable for Kubernetes, Docker, or monitoring systems.

import { RedisChecker } from "redis-messaging";

const checker = new RedisChecker(client);

const result = await checker.check();

Example

Map {
  "status" => "UP",
  "connected" => true,
  "responseTime" => 4
}

You can customize the service name and timeout.

const checker = new RedisChecker(
    client,
    "cache",
    3000
);

API

Publisher

class Publisher<T> {
    publish(data: T): Promise<number>;
}

RedisPublisher

class RedisPublisher<T> {
    publish(
        data: T,
        headers?: Record<string, string>
    ): Promise<number>;
}

Subscriber

class Subscriber<T, R> {
    subscribe(
        process: (data: T) => Promise<R>
    ): Promise<void>;
}

RedisSubscriber

class RedisSubscriber<T, R> {
    subscribe(
        process: (
            data: T,
            headers?: Record<string, string>
        ) => Promise<R>
    ): Promise<void>;
}

RedisChecker

class RedisChecker {
    check(): Promise<Map<string, any>>;
}

Architecture

                    Redis Server
                         ▲
                         │
                Redis Pub/Sub Channel
                         ▲
         ┌───────────────┴───────────────┐
         │                               │
  RedisPublisher<T>             RedisSubscriber<T>
         ▲                               │
         │                               ▼
     Publisher<T>                  Business Logic

Why redis-messaging?

Unlike using the Redis client directly, redis-messaging provides:

  • Strong typing
  • Cleaner APIs
  • Header support
  • Pluggable serialization
  • Consistent programming model
  • Built-in health checking
  • Enterprise-ready abstractions

Use Cases

  • Event-driven architecture
  • Internal microservice communication
  • Notification systems
  • Cache invalidation events
  • Lightweight messaging
  • Background workers
  • Real-time updates

Limitations

redis-messaging is built on Redis Pub/Sub.

Redis Pub/Sub is designed for lightweight messaging and has the following characteristics:

  • No message persistence
  • No acknowledgements
  • No retries
  • No dead-letter queue
  • Subscribers only receive messages while connected

If durable messaging is required, consider technologies such as Kafka, RabbitMQ, ActiveMQ, or Redis Streams.


Requirements

  • Node.js 18+
  • Redis 6+
  • TypeScript 5+

License

MIT