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

@heady/redis-client

v1.0.1

Published

![Language](https://img.shields.io/badge/language-TypeScript-blue) ![License](https://img.shields.io/badge/license-MIT-green) ![Version](https://img.shields.io/badge/version-1.0.1-orange)

Readme

Redis Client

Language License Version

Redis Client is a lightweight, type-safe wrapper for ioredis. It solves the problem of scaling Redis infrastructure by automatically routing Write operations to a Primary node and Read operations to Replica nodes.

📑 Table of Contents


✨ Features

  • Automatic Traffic Splitting: Writes (set, del, expire) are sent to the Primary; Reads (get, scan, hget, keys) are sent to Replicas.
  • Type Safety: Built with TypeScript, providing full IntelliSense and type checking out of the box.
  • Performance: Offloads expensive read operations (like SCAN) from your Master node to prevent blocking critical write traffic.
  • Flexible Access: Exposes the underlying ioredis instances if you need to run custom or unsupported commands.

🔧 Prerequisites

Before you begin, ensure you have met the following requirements:

  • Node.js (v14 or higher)
  • Redis: A Redis setup with at least one Master and one Replica (e.g., AWS ElastiCache Cluster Mode Disabled).

🚀 Installation

  1. Install the package and the peer dependency:
    npm install @heady/redis-client

💡 Usage

import { RedisClient } from '@heady/redis-client';

// 1. Initialize with separate endpoints
const redis = new RedisClient({
  primary: {
    host: 'primary-node.redis.aws.internal',
    port: 6379,
  },
  replica: {
    host: 'replica-node.redis.aws.internal',
    port: 6379,
  }
});

async function main() {
  // ✍️ WRITE: Automatically routed to Primary
  await redis.set('user:101', 'John Doe', 3600); 
  console.log('User saved to Primary node');

  // 📖 READ: Automatically routed to Replica
  const user = await redis.get('user:101');
  console.log('User read from Replica node:', user);

  // 🧹 CLEANUP
  await redis.disconnect();
}

main();

⚙️ Configuration

The RedisClient constructor accepts a configuration object with two keys: primary and replica. Both accept standard ioredis options.

| Property | Type | Description | |:-----|:--------:|------:| | primary | RedisOptions | Configuration for the Master (Write) node. | | replica | RedisOptions | Configuration for the Read Replica

Example Config Object:

{
  primary: { host: '127.0.0.1', port: 6379, password: 'auth' },
  replica: { host: '127.0.0.1', port: 6380, password: 'auth' }
}

🏗 Architecture

This library implements the Read/Write Splitting pattern:

  1. Command Interception: The client checks the method being called (e.g., set vs get).
  2. Routing: * Mutating commands → Primary Connection
    • Read-only commands → Replica Connection
  3. Result: This ensures high availability and prevents heavy read queries from slowing down data ingestion.

🧪 Running Tests

This project uses Jest with ts-jest for unit testing. The tests mock ioredis to ensure traffic is routed to the correct connection without needing a real Redis instance.

To run the test suite:

npm test

Expected Output:


 PASS  test/client.test.ts
  RedisClient
    ✓ should create two separate Redis connections
    ✓ set() should call primary node
    ✓ get() should call replica node

📜 License

This project is licensed under the MIT License - see the LICENSE file for details.