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

@cachehub/upstash-redis-cache

v1.0.2

Published

Upstash Redis cache implementation for CacheHub with hybrid string and TypeCacheKey support.

Readme

@cachehub/upstash-redis-cache

Upstash Redis cache implementation for CacheHub with hybrid string and TypeCacheKey support.

Installation

pnpm add @cachehub/upstash-redis-cache @upstash/redis

Usage

To use the Upstash Redis cache adapter in your application, follow these steps:

  1. Import the Upstash Redis cache package to register it with the factory. For example:
    import '@cachehub/upstash-redis-cache';
  2. Create a cache instance using the factory.
  3. Use the cache instance to set, get, delete, and check cache entries.
import '@cachehub/upstash-redis-cache';
import { UpstashRedisCacheFactory } from '@cachehub/upstash-redis-cache';

const factory = new UpstashRedisCacheFactory();
const cache = await factory.createCache({
  CACHE_TYPE: 'upstash-redis-cache',
  REDIS_URL: process.env.REDIS_URL!,
  REDIS_TOKEN: process.env.REDIS_TOKEN!,
});

// Set and get primitive types
await cache.set<string>('stringKey', 'value');
const stringValue = await cache.get<string>('stringKey');

await cache.set<number>('numberKey', 42);
const numberValue = await cache.get<number>('numberKey');

await cache.set<boolean>('booleanKey', true);
const booleanValue = await cache.get<boolean>('booleanKey');

// Set and get complex objects
interface User {
  id: number;
  name: string;
  email: string;
}

const user: User = {
  id: 1,
  name: 'John Doe',
  email: '[email protected]'
};

await cache.set<User>('userKey', user);
const userValue = await cache.get<User>('userKey');

// Set and get arrays
await cache.set<string[]>('arrayKey', ['a', 'b', 'c']);
const arrayValue = await cache.get<string[]>('arrayKey');

// Basic cache operations
await cache.delete('key');
const exists = await cache.has('key');

TypeCacheKey Support

The adapter supports structured cache keys for advanced scenarios:

import type { TypeCacheKey } from '@cachehub/core';

// Using structured cache keys
const licenseKey: TypeCacheKey = {
  namespace: 'license',
  id: 'ABC-123',
  context: {
    action: 'activation',
    domain: 'example.com',
    ipAddress: '192.168.1.1'
  }
};

// Store with structured key
await cache.set(licenseKey, { token: 'xyz789', expires: Date.now() + 3600000 });

// Retrieve with structured key
const licenseData = await cache.get(licenseKey);

// Pattern deletion - delete all cache entries for license ABC-123
await cache.delete({
  namespace: 'license',
  id: 'ABC-123'
  // Omitting context deletes ALL entries matching namespace and id
});

// Delete all license entries
await cache.delete({
  namespace: 'license'
  // Omitting id deletes ALL entries in the namespace
});

Pattern Deletion Support

The UpstashRedisCache provides native pattern deletion using Redis SCAN operations:

✅ All Deletion Patterns Supported:

// Exact key deletion with TypeCacheKey
await cache.delete({ 
  namespace: 'license', 
  id: 'ABC-123',
  context: { action: 'activation', domain: 'example.com' }
});

// Namespace + ID deletion (deletes all contexts for that ID)
await cache.delete({ 
  namespace: 'license', 
  id: 'ABC-123' 
});

// Partial context deletion (deletes all entries matching partial context)
await cache.delete({ 
  namespace: 'license', 
  context: { action: 'activation' }  // Deletes all activations regardless of ID
});

// Namespace-only deletion (deletes all entries in namespace)
await cache.delete({ 
  namespace: 'license' 
});

// String key deletion
await cache.delete('exact-string-key');

How It Works:

  • Redis SCAN: Uses native Redis SCAN operations with MATCH patterns
  • Immediate Consistency: Deletions complete immediately using DEL command
  • Efficient Batching: Processes keys in batches of 100 for optimal performance
  • Native Redis Operations: Leverages Redis cluster-safe operations

Key Serialization

TypeCacheKey objects are automatically serialized to deterministic strings:

  • { namespace: 'license', id: '123' }'license|123'
  • { namespace: 'license', id: '123', context: { action: 'activation' } }'license|123|action:activation'
  • Context keys are sorted alphabetically for consistency

Configuration

The Upstash Redis cache requires the following configuration:

interface TypeUpstashRedisCacheConfig {
  /**
   * The Redis URL
   */
  REDIS_URL: string;

  /**
   * The Redis token
   */
  REDIS_TOKEN: string;

  /**
   * Optional prefix for cache keys
   */
  keyPrefix?: string;
}

Testing

To run the tests, create a .env file with your Upstash Redis credentials:

REDIS_URL=your_redis_url
REDIS_TOKEN=your_redis_token

Then run:

pnpm test