Registry / devops / ondc-automation-cache-lib

ondc-automation-cache-lib

JSON →
library2.1.0jsnpmunverified

A Redis-based caching library v2.1.0 for ONDC (Open Network for Digital Commerce) automation tasks, providing specialized cache services for CRUD operations across multiple databases. It offers per-domain isolation (API, Mock, Reporting, Config, Console) using separate Redis DB indices, with built-in Pub/Sub support. Unlike generic Redis clients, it provides typed service classes for structured caching patterns. Requires a running Redis instance (6.2+ recommended). Ships TypeScript definitions. Active development with regular releases.

npm install ondc-automation-cache-lib
INSTALL
IMPORT
SIG · ONDC-AUTOMATION-CA
O
ondc-automation-cache-lib
devopsjavascriptv2.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RedisService
import { RedisService } from 'ondc-automation-cache-lib'
const RedisService = require('ondc-automation-cache-lib').RedisService
ESM-only, TypeScript types included; library is not CommonJS compatible. Use named import, not default.
ApiServiceCache
import { ApiServiceCache } from 'ondc-automation-cache-lib'
import ApiServiceCache from 'ondc-automation-cache-lib'
Named export, not default. Requires RedisService instance passed to constructor.
MockServiceCache
import { MockServiceCache } from 'ondc-automation-cache-lib'
var MockServiceCache = require('ondc-automation-cache-lib').MockServiceCache
ESM-only named export. CommonJS require() will not work.
ConfigCacheService
import { ConfigCacheService } from 'ondc-automation-cache-lib'
Named export, same pattern as other services.

Demonstrates basic key-value operations with RedisService and specialized caching using ApiServiceCache, including setup, usage, and cleanup.

import { RedisService, ApiServiceCache } from 'ondc-automation-cache-lib'; async function main() { // RedisService is initialized via environment variables: REDIS_HOST, REDIS_PORT, etc. // Set a key await RedisService.setKey('hello', 'world'); const value = await RedisService.getKey('hello'); console.log(value); // 'world' // Use specialized cache const apiCache = new ApiServiceCache(RedisService); await apiCache.setSessionIdFromAPIService('session-123', { data: 'test' }); const session = await apiCache.getSessionIdFromAPIService('session-123'); console.log(session); // Cleanup await RedisService.disconnect(); } main().catch(console.error);
Debug
Known issues
breakingWhen using TypeScript, do not import Redis as default import; library provides named exports only. CommonJS require() will fail in Node ESM environments.
fix
Use import { RedisService } from 'ondc-automation-cache-lib'
affects: >=2.0.0
gotchaRedisService is a singleton; calling useDb() changes the selected database globally, affecting all subsequent operations.
fix
Use separate RedisService instances for concurrent access to different databases, or call useDb() before each operation group.
affects: >=1.0.0
gotchaCache operations return null or false on failure instead of throwing errors; check return values to avoid silent failures.
fix
Always check return values: const result = await RedisService.getKey('key'); if (result === null) { handleError(); }
affects: >=1.0.0
deprecatedRedis v4 introduced breaking changes; this library may require a specific version of the 'redis' package (^3.1.2).
fix
Install redis@3.1.2 or check package.json peerDependencies.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: RedisService.setKey is not a function
Default import instead of named import when using ESM.
fix
Change to import { RedisService } from 'ondc-automation-cache-lib'
Error: Redis connection error - getaddrinfo ENOTFOUND redis
Missing REDIS_HOST environment variable or Redis not running.
fix
Set REDIS_HOST to 'localhost' or your Redis server address, and ensure Redis is running.
Module not found: Can't resolve 'ondc-automation-cache-lib'
Package not installed or incorrect import in JavaScript (non-TypeScript) project.
fix
Run npm install ondc-automation-cache-lib and use the TypeScript-style import even in .js files (if using Babel), or configure module bundler.
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
redisrequiredUnderlying Redis client for all cache operations
Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
2
Resources
ondc-automation-cache-lib — npm install ondc-automation-cache-lib · libregistry