{"id":44500,"library":"cache-service-redis","title":"cache-service-redis","description":"A Redis plugin for cache-service and a standalone Redis wrapper for Node.js (v2.0.2). Provides features like background refresh, automatic serialization/deserialization of objects, flexible Redis connection configuration (via env var, URL, or explicit params), and built-in logging with verbose flag. Compared to vanilla node_redis, it offers a more logical API (e.g., mset() accepts an object and supports per-key expiration). Compatible with cache-service and superagent-cache, and includes redis mock support for testing. The library is stable but in maintenance mode; no recent updates.","status":"maintenance","version":"2.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/jpodwys/cache-service-redis","tags":["javascript","cache-service","cache","node","redis"],"install":[{"cmd":"npm install cache-service-redis","lang":"bash","label":"npm"},{"cmd":"yarn add cache-service-redis","lang":"bash","label":"yarn"},{"cmd":"pnpm add cache-service-redis","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Underlying Redis client used for all operations","package":"redis","optional":false},{"reason":"Optional integration with cache-service for multi-tier caching","package":"cache-service","optional":true}],"imports":[{"note":"This package is CJS-only. ESM import will fail.","wrong":"import CacheServiceRedis from 'cache-service-redis';","symbol":"default","correct":"const CacheServiceRedis = require('cache-service-redis');"},{"note":"The module exports the class directly.","wrong":"const redisCache = new CacheServiceRedis.RedisCache({ redisEnv: 'REDISCLOUD_URL' });","symbol":"constructor","correct":"const redisCache = new CacheServiceRedis({ redisEnv: 'REDISCLOUD_URL' });"},{"note":"Expiration (optional) is passed as a number (seconds), not an object.","wrong":"redisCache.set('key', 'value', { expiration: 3600 });","symbol":"instance methods","correct":"redisCache.set('key', 'value', 3600);"}],"quickstart":{"code":"const CacheServiceRedis = require('cache-service-redis');\n\nconst redisCache = new CacheServiceRedis({\n  redisUrl: process.env.REDIS_URL ?? 'redis://localhost:6379',\n  defaultExpiration: 3600,\n  verbose: false\n});\n\nredisCache.set('mykey', { data: 'hello' }, 60)\n  .then(() => redisCache.get('mykey'))\n  .then(result => console.log(result)) // { data: 'hello' }\n  .catch(err => console.error(err));","lang":"javascript","description":"Instantiates cache-service-redis with a Redis URL, sets a serialized object with 60s TTL, then retrieves it."},"warnings":[{"fix":"Use { redisData: { port: 6379, hostname: 'localhost', auth: 'pass' } } instead of a single string.","message":"v2.x changed the constructor signature; `redisData` is now an object with `port`, `hostname`, `auth` instead of a flat string.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Use `redisUrl` with a full connection string or `redisData` object.","message":"The `redisEnv` option reads from `process.env[redisEnv]`; this is fragile and not recommended for production. Prefer `redisUrl` or `redisData`.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Set `backgroundRefreshInterval` < `backgroundRefreshMinTtl` (defaults: 60000 < 70000).","message":"If `backgroundRefreshInterval` >= `backgroundRefreshMinTtl`, an exception is thrown unless `backgroundRefreshIntervalCheck` is false.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set verbose on cache-service instance instead.","message":"When used with `cache-service`, the `verbose` property is overridden by `cache-service`'s verbose flag.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'accept':61 'api':58 'automat':25 'background':23 'built':42 'built-in':41 'cach':2,10,73,78,99,101 'cache-servic':9,72,98 'cache-service-redi':1 'compar':48 'compat':70 'configur':32 'connect':31 'e.g':59 'env':34 'expir':69 'explicit':38 'featur':21 'flag':47 'flexibl':29 'includ':80 'javascript':97 'key':68 'librari':87 'like':22 'log':44 'logic':57 'mainten':92 'mock':82 'mode':93 'mset':60 'node':51,102 'node.js':18 'object':28,63 'offer':54 'param':39 'per':67 'per-key':66 'plugin':7 'provid':20 'recent':95 'redi':4,6,15,30,52,81,103 'refresh':24 'serialization/deserialization':26 'servic':3,11,74,100 'stabl':89 'standalon':14 'superag':77 'superagent-cach':76 'support':65,83 'test':85 'updat':96 'url':36 'v2.0.2':19 'vanilla':50 'var':35 'verbos':46 'via':33 'wrapper':16","created_at":"2026-06-07T12:50:26.599834+00:00","updated_at":"2026-06-07T12:50:26.599834+00:00","problems":[{"fix":"Use `const CacheServiceRedis = require('cache-service-redis');`","cause":"Using ES import (`import CacheServiceRedis from 'cache-service-redis'`) on a CJS module.","error":"TypeError: CacheServiceRedis is not a constructor"},{"fix":"Ensure Redis is running and check connection parameters (host, port, auth).","cause":"Redis server not running or connection config is wrong.","error":"Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED"},{"fix":"Verify import: `const CacheServiceRedis = require('cache-service-redis');` and instantiate with `new CacheServiceRedis(...)`.","cause":"Instance created with incorrect options or not using the class directly.","error":"TypeError: redisCache.set is not a function"}],"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/jpodwys/cache-service-redis#readme","github":"https://github.com/jpodwys/cache-service-redis","docs":null,"changelog":null,"pypi":null,"npm":"cache-service-redis","openapi_spec":null,"status_page":null,"smithery":null,"categories":["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}}