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

@edirect/redis

v11.0.50

Published

Redis client module for eDirect NestJS applications. Wraps the `redis` Node.js client and exposes a `RedisService` with high-level methods for key-value, hash, and set operations — all with automatic JSON serialization and centralized error logging.

Readme

@edirect/redis

Redis client module for eDirect NestJS applications. Wraps the redis Node.js client and exposes a RedisService with high-level methods for key-value, hash, and set operations — all with automatic JSON serialization and centralized error logging.

Features

  • Global module — register once, inject RedisService anywhere
  • Automatic JSON serialization/deserialization for stored values
  • TTL support with configurable expiry types (EX, PX, EXAT, PXAT)
  • Hash operations (hget, hgetall)
  • Conditional set (setnx) for atomic operations
  • Integrated error logging via @edirect/logger
  • Health check via asyncPing()

Installation

pnpm add @edirect/redis
# or
npm install @edirect/redis

Usage

Register in your AppModule

import { Module } from '@nestjs/common';
import { ConfigModule } from '@edirect/config';
import { LoggerModule } from '@edirect/logger';
import { RedisModule } from '@edirect/redis';

@Module({
  imports: [
    ConfigModule,
    LoggerModule.register({ output: 'console' }),
    RedisModule,
  ],
})
export class AppModule {}

Because RedisModule is decorated with @Global(), you only need to import it once at the root module.

Inject and use RedisService

import { Injectable } from '@nestjs/common';
import { RedisService } from '@edirect/redis';

@Injectable()
export class CacheService {
  constructor(private readonly redis: RedisService) {}

  async cachePolicy(policyId: string, data: object): Promise<void> {
    // Store with 5-minute TTL
    await this.redis.set(`policy:${policyId}`, data, 300);
  }

  async getPolicy(policyId: string): Promise<object | null> {
    return this.redis.get(`policy:${policyId}`) as Promise<object | null>;
  }

  async isAlive(): Promise<boolean> {
    return this.redis.asyncPing();
  }
}

Environment Variables

| Variable | Description | Required | | ----------- | ----------------------------------------------------------------------- | -------- | | REDIS_URL | Redis connection URL (e.g., redis://localhost:6379) | Yes | | REDIS_TTL | Default TTL in seconds when ttl param is omitted (use 0 for no TTL) | No |

API

RedisService

| Method | Signature | Description | | ----------- | ---------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- | | get | (key: string): Promise<string \| object \| null> | Get and JSON-parse a value by key | | mget | (keys: string[]): Promise<string[] \| object[]> | Get and JSON-parse multiple keys | | set | (key: string, data: object \| string, ttl?: number, ttlType?: 'EX' \| 'PX' \| 'EXAT' \| 'PXAT'): Promise<void> | Set a value with optional TTL. Falls back to REDIS_TTL env. | | del | (key: string): Promise<void> | Delete a key | | setnx | (key: string, data: object \| string): Promise<boolean> | Set only if the key does not exist. Returns true if set. | | hget | (hash: string, field: string): Promise<string \| null> | Get a single field from a hash | | hgetall | (hash: string): Promise<{ [key: string]: string }> | Get all fields from a hash | | keys | (pattern: string): Promise<string \| string[]> | Find keys matching a pattern | | asyncPing | (): Promise<boolean> | Returns true if Redis responds to PING |

TTL Types

| ttlType | Description | | -------------- | ------------------------------ | | EX (default) | Seconds from now | | PX | Milliseconds from now | | EXAT | Unix timestamp in seconds | | PXAT | Unix timestamp in milliseconds |

Examples

// Store a string with 1-hour TTL
await redis.set('session:abc', 'user-data', 3600);

// Store an object (auto-serialized to JSON)
await redis.set('user:123', { name: 'John', role: 'admin' }, 600);

// Read back (auto-deserialized from JSON)
const user = await redis.get('user:123'); // → { name: 'John', role: 'admin' }

// Atomic set (only if key doesn't exist)
const wasSet = await redis.setnx('lock:job-1', 'worker-1');

// Hash operations
await redis.hget('config:th-broker', 'maxPolicies');
const allConfig = await redis.hgetall('config:th-broker');

// Wildcard key lookup
const sessionKeys = await redis.keys('session:*');