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 🙏

© 2025 – Pkg Stats / Ryan Hefner

ondc-automation-cache-lib

v2.1.0

Published

redis cache lib for CRUD operations

Readme

automation-cache

A Redis-based caching library with multiple specialized cache services for different purposes.

Installation

npm install ondc-automation-cache-lib

Configuration

Create a .env file in your project root:

REDIS_HOST=redis      # Use 'localhost' if running Redis locally
REDIS_PORT=6379
REDIS_USERNAME=       # Optional
REDIS_PASSWORD=       # Optional

Usage

Basic Redis Operations

import { RedisService } from "ondc-automation-cache-lib";

// Basic key-value operations
await RedisService.setKey("example-key", "example-value");
const value = await RedisService.getKey("example-key");
const exists = await RedisService.keyExists("example-key");
await RedisService.deleteKey("example-key");

// Database selection
RedisService.useDb(0); // Switch to database 0

// Pub/Sub functionality
RedisService.subscribeToDb(0, (message) => {
  console.log("Received message:", message);
});

Specialized Cache Services

The library provides several specialized cache services for different purposes:

API Service Cache (DB 0)

import { ApiServiceCache, RedisService } from "ondc-automation-cache-lib";

const apiCache = new ApiServiceCache(RedisService);

// Session management
await apiCache.setSessionIdFromAPIService("sessionId", "sessionData");
const session = await apiCache.getSessionIdFromAPIService("sessionId");

// Subscriber management
await apiCache.setSubscriberCache("subscriberUrl", "subscriberData");
const subscriber = await apiCache.getSubscriberCache("subscriberUrl");

// Transaction management
await apiCache.setTransactionCache("txnId", "transactionData");
const transaction = await apiCache.getTransactionCache("txnId");

Mock Service Cache (DB 1)

import { MockServiceCache, RedisService } from "ondc-automation-cache-lib";

const mockCache = new MockServiceCache(RedisService);
await mockCache.setMockData("mockId", "mockData");
const mockData = await mockCache.getMockData("mockId");

Reporting Cache Service (DB 2)

import { ReportingCacheService, RedisService } from "ondc-automation-cache-lib";

const reportingCache = new ReportingCacheService(RedisService);
await reportingCache.setReportingData("reportId", "reportData");
const reportData = await reportingCache.getReportingData("reportId");

Config Cache Service (DB 3)

import { ConfigCacheService, RedisService } from "ondc-automation-cache-lib";

const configCache = new ConfigCacheService(RedisService);
await configCache.setConfigData("configId", "configData");
const configData = await configCache.getConfigData("configId");

Console Cache Service (DB 4)

import { ConsoleCacheService, RedisService } from "ondc-automation-cache-lib";

const consoleCache = new ConsoleCacheService(RedisService);
await consoleCache.setConsoleData("consoleId", "consoleData");
const consoleData = await consoleCache.getConsoleData("consoleId");

Database Index Map

  • DB 0: API Service Cache
  • DB 1: Mock Service Cache
  • DB 2: Reporting Cache Service
  • DB 3: Config Cache Service
  • DB 4: Console Cache Service

Docker Support

If you're using Docker, include Redis in your docker-compose.yml:

services:
  redis:
    image: redis:6.2
    container_name: redis
    ports:
      - "6379:6379"
    networks:
      - automation-network

Cleanup

To properly close Redis connections (important for testing):

await RedisService.disconnect();

Error Handling

All cache operations return null or false on failure rather than throwing errors. Check return values to handle errors appropriately.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

import { RedisService } from "ondc-automation-cache-lib";

// Select and use database 0
RedisService.useDb(0);

// subscribe to the db and listen to the message
RedisService.subscribeToDb(0, (message) => {
  console.log("message", message);
});

(async () => {
  // Set a key with TTL
  const setResult = await RedisService.setKey(
    "example-key",
    "example-value",
    3600
  );
  console.log("Set key result:", setResult); // Outputs: true

  // Get a key
  const value = await RedisService.getKey("example-key");
  console.log("Value:", value); // Outputs: example-value

  // Check if a key exists
  const exists = await RedisService.keyExists("example-key");
  console.log("Key exists:", exists); // Outputs: true

  // Delete a key
  const deleteResult = await RedisService.deleteKey("example-key");
  console.log("Delete key result:", deleteResult); // Outputs: true

  // Check if the key exists after deletion
  const existsAfterDelete = await RedisService.keyExists("example-key");
  console.log("Key exists after delete:", existsAfterDelete); // Outputs: false
})();