{"id":45656,"library":"ondc-automation-cache-lib","title":"ONDC Automation Cache Library","description":"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.","status":"active","version":"2.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/orgs/ONDC-Official/automation-cache","tags":["javascript","automation-cache","ondc-redis-cache","ondc-automation-cache-lib","typescript"],"install":[{"cmd":"npm install ondc-automation-cache-lib","lang":"bash","label":"npm"},{"cmd":"yarn add ondc-automation-cache-lib","lang":"bash","label":"yarn"},{"cmd":"pnpm add ondc-automation-cache-lib","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Underlying Redis client for all cache operations","package":"redis","optional":false}],"imports":[{"note":"ESM-only, TypeScript types included; library is not CommonJS compatible. Use named import, not default.","wrong":"const RedisService = require('ondc-automation-cache-lib').RedisService","symbol":"RedisService","correct":"import { RedisService } from 'ondc-automation-cache-lib'"},{"note":"Named export, not default. Requires RedisService instance passed to constructor.","wrong":"import ApiServiceCache from 'ondc-automation-cache-lib'","symbol":"ApiServiceCache","correct":"import { ApiServiceCache } from 'ondc-automation-cache-lib'"},{"note":"ESM-only named export. CommonJS require() will not work.","wrong":"var MockServiceCache = require('ondc-automation-cache-lib').MockServiceCache","symbol":"MockServiceCache","correct":"import { MockServiceCache } from 'ondc-automation-cache-lib'"},{"note":"Named export, same pattern as other services.","symbol":"ConfigCacheService","correct":"import { ConfigCacheService } from 'ondc-automation-cache-lib'"}],"quickstart":{"code":"import { RedisService, ApiServiceCache } from 'ondc-automation-cache-lib';\n\nasync function main() {\n  // RedisService is initialized via environment variables: REDIS_HOST, REDIS_PORT, etc.\n  // Set a key\n  await RedisService.setKey('hello', 'world');\n  const value = await RedisService.getKey('hello');\n  console.log(value); // 'world'\n\n  // Use specialized cache\n  const apiCache = new ApiServiceCache(RedisService);\n  await apiCache.setSessionIdFromAPIService('session-123', { data: 'test' });\n  const session = await apiCache.getSessionIdFromAPIService('session-123');\n  console.log(session);\n\n  // Cleanup\n  await RedisService.disconnect();\n}\n\nmain().catch(console.error);","lang":"typescript","description":"Demonstrates basic key-value operations with RedisService and specialized caching using ApiServiceCache, including setup, usage, and cleanup."},"warnings":[{"fix":"Use import { RedisService } from 'ondc-automation-cache-lib'","message":"When using TypeScript, do not import Redis as default import; library provides named exports only. CommonJS require() will fail in Node ESM environments.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Use separate RedisService instances for concurrent access to different databases, or call useDb() before each operation group.","message":"RedisService is a singleton; calling useDb() changes the selected database globally, affecting all subsequent operations.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always check return values: const result = await RedisService.getKey('key'); if (result === null) { handleError(); }","message":"Cache operations return null or false on failure instead of throwing errors; check return values to avoid silent failures.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Install redis@3.1.2 or check package.json peerDependencies.","message":"Redis v4 introduced breaking changes; this library may require a specific version of the 'redis' package (^3.1.2).","severity":"deprecated","affected_versions":">=2.0.0"}],"env_vars":null,"search_vec":"'6.2':71 'across':28 'activ':76 'api':37 'autom':2,19,83,91 'automation-cach':82 'base':8 'built':49 'built-in':48 'cach':3,9,23,64,84,88,92 'class':61 'client':56 'commerc':18 'config':40 'consol':41 'crud':26 'databas':30 'db':45 'definit':75 'develop':77 'digit':17 'domain':35 'generic':54 'indic':46 'instanc':70 'isol':36 'javascript':81 'lib':93 'librari':4,10 'mock':38 'multipl':29 'network':15 'offer':32 'ondc':1,13,86,90 'ondc-automation-cache-lib':89 'ondc-redis-cach':85 'open':14 'oper':27 'pattern':65 'per':34 'per-domain':33 'provid':21,58 'pub/sub':51 'recommend':72 'redi':7,44,55,69,87 'redis-bas':6 'regular':79 'releas':80 'report':39 'requir':66 'run':68 'separ':43 'servic':24,60 'ship':73 'special':22 'structur':63 'support':52 'task':20 'type':59 'typescript':74,94 'unlik':53 'use':42 'v2.1.0':11","created_at":"2026-06-07T12:56:05.047306+00:00","updated_at":"2026-06-07T12:56:05.047306+00:00","problems":[{"fix":"Change to import { RedisService } from 'ondc-automation-cache-lib'","cause":"Default import instead of named import when using ESM.","error":"TypeError: RedisService.setKey is not a function"},{"fix":"Set REDIS_HOST to 'localhost' or your Redis server address, and ensure Redis is running.","cause":"Missing REDIS_HOST environment variable or Redis not running.","error":"Error: Redis connection error - getaddrinfo ENOTFOUND redis"},{"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.","cause":"Package not installed or incorrect import in JavaScript (non-TypeScript) project.","error":"Module not found: Can't resolve 'ondc-automation-cache-lib'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/ONDC-Official/automation-cache#readme","github":"https://github.com/orgs/ONDC-Official/automation-cache","docs":null,"changelog":null,"pypi":null,"npm":"ondc-automation-cache-lib","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops","storage"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}