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

@myko.pk/redis

v1.5.0

Published

Redis client and Bloom filter for MYKO NestJS services

Downloads

1,211

Readme

📑 Table of Contents

📝 Description

@myko.pk/redis provides a standardised Redis client and Bloom filter for MYKO NestJS services.

  • Dual-mode Redis — auto-detects between ioredis (TCP) and Upstash Redis (REST) at startup
  • Auto-namespacing — every key is prefixed with {serviceName}: to prevent cross-service collisions
  • Bloom filter — in-memory probabilistic data structure for fast existence checks

✨ Key Features

  • 🧩 Dual Client — Works with both ioredis (Railway Redis) and Upstash Redis REST API
  • 🏷️ Namespaced Keys — Automatic {serviceName}: prefix on every operation
  • 📦 Pipeline SupportsetMultiple and Upstash pipeline for batch writes
  • 🔍 Pattern Invalidation — Wildcard-based cache invalidation via SCAN + DEL
  • 🪣 Bloom Filter — Configurable capacity/FP rate, MD5 hashing, load from DB
  • 🏗️ Global Modules — Both modules are @Global() — import once, inject anywhere
  • 📘 Fully Typed — Full TypeScript support with typed interfaces

⚡ Quick Start

npm install @myko.pk/redis

Redis

import { Module } from '@nestjs/common';
import { RedisModule } from '@myko.pk/redis';

@Module({
  imports: [RedisModule],
})
export class AppModule {}
import { Injectable } from '@nestjs/common';
import { RedisService } from '@myko.pk/redis';

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

  async cacheUser(id: string, data: any) {
    await this.redis.setNamespaced(`user:${id}`, data, { ex: 3600 });
  }

  async getUser(id: string) {
    return this.redis.getNamespaced(`user:${id}`);
  }
}

Keys are automatically namespaced: my-service:user:abc123

Bloom Filter

import { Module } from '@nestjs/common';
import { BloomFilterModule } from '@myko.pk/redis/bloom';

@Module({
  imports: [BloomFilterModule],
})
export class AppModule {}
import { Injectable, OnModuleInit } from '@nestjs/common';
import { BloomFilterService } from '@myko.pk/redis/bloom';

@Injectable()
export class MyService implements OnModuleInit {
  constructor(private readonly bloom: BloomFilterService) {}

  async onModuleInit() {
    await this.bloom.initialize(async () => {
      const users = await this.userRepo.findAll();
      return users.map(u => `email:${u.email.toLowerCase()}`);
    });
  }

  async isEmailUsed(email: string): Promise<boolean> {
    return this.bloom.has(`email:${email.toLowerCase()}`);
  }
}

Modules

RedisModule

| Export | Description | |--------|-------------| | RedisModule | @Global() module — auto-configures from env | | RedisService | Injectable dual-mode Redis client |

Environment Variables:

| Variable | Purpose | |----------|---------| | REDIS_PUBLIC_URL | Use ioredis (Railway Redis) | | UPSTASH_REDIS_REST_URL + UPSTASH_REDIS_REST_TOKEN | Use Upstash Redis REST | | APP_NAME | Namespace prefix for all keys |

RedisService Methods:

| Method | Description | |--------|-------------| | setNamespaced(key, value, opts?) | Set with auto-namespacing + TTL | | getNamespaced(key) | Get and deserialize | | getAndDeleteNamespaced(key) | Atomic GETDEL (Redis 6.2+) | | delNamespaced(key) | Delete | | existsNamespaced(key) | Check existence | | expireNamespaced(key, sec) | Set TTL | | setMultiple(entries) | Pipeline batch set | | invalidatePattern(pattern) | Wildcard invalidation (SCAN + DEL) | | getServiceKeys(pattern?) | List all keys for this service | | clearServiceCache() | Delete all keys for this service | | ping() | Health check | | lpush(key, ...values) | Push to list head | | rpop(key) | Pop from list tail | | llen(key) | List length |

BloomFilterModule

| Export | Description | |--------|-------------| | BloomFilterModule | @Global() module | | BloomFilterService | Injectable in-memory Bloom filter |

BloomFilterService Methods:

| Method | Description | |--------|-------------| | initialize(fetcher) | Load items from async callback | | has(item) | Check if item might exist | | add(item) | Insert single item | | addMany(items) | Insert multiple items | | info() | Get filter stats | | clear() | Reset filter | | estimatedFalsePositiveRate() | Current FP rate estimate |

API Reference

Types

| Type | Source | Description | |------|--------|-------------| | RedisSetOptions | @myko.pk/types | { ex?, px?, nx?, xx? } | | BloomFilterOptions | ./bloom/bloom-filter.types | { expectedElements?, falsePositiveRate? } | | BloomFilterInfo | ./bloom/bloom-filter.types | Filter stats |

DI Tokens

None — both modules are @Global() and their services are injectable directly.

🚀 Available Scripts

  • buildnpm run build
  • devnpm run dev
  • typechecknpm run typecheck

👥 Contributors

See the full list of contributors →

👥 Contributing

Contributions are welcome! Here's the standard flow:

  1. Fork the repository
  2. Clone your fork: git clone https://github.com/mykopk/redis.git
  3. Branch: git checkout -b feature/your-feature
  4. Commit: git commit -m 'feat: add some feature'
  5. Push: git push origin feature/your-feature
  6. Open a pull request

📜 License

This project is licensed under the MIT License.

MYKO Pakistan

Detail Information Website myko.pk Email [email protected] About Building digital infrastructure and super-app experiences for millions of users across Pakistan. Built with ❤️ in Pakistan 🇵🇰