Registry / storage / redis-memoizer

redis-memoizer

JSON →
library1.0.2jsnpmunverified

An asynchronous function memoizer for Node.js using Redis as a shared cache store, with configurable TTL. Version 1.0.2 (stable) works with promises and async/await on Node 8+. It provides a drop-in caching layer for heavy async functions, with cache shared across processes via Redis. Differentiators: network-available cache, TTL-based expiration, and support for both async/await and promises. Compared to other memoizers, it uses an external Redis store, making it suitable for distributed systems.

npm install redis-memoizer
INSTALL
IMPORT
SIG · REDIS-MEMOIZER
R
redis-memoizer
storagejavascriptv1.0.2
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.

memoize
import memoize from 'redis-memoizer'; (ESM) or const memoize = require('redis-memoizer');
import { memoize } from 'redis-memoizer';
Package exports a function that takes a redis client, not a named export. Use default import.
memoized function
const memoizedFunc = memoize(asyncFunc, { name: 'funcName' });
const memoizedFunc = memoize(asyncFunc);
The options object with 'name' is required. Missing name will throw.
promise style
memoize(funcReturningPromise, { name: 'func' });
memoize(funcWithCallback, { name: 'func' });
Only supports functions that return a promise or are async. Callback-style functions not supported in v1.

Shows initializing with Redis client, memoizing an async function, and measuring performance improvement on cached call.

const redis = require('redis'); const memoize = require('redis-memoizer')(redis.createClient()); async function expensiveOp(userId) { // simulate DB call return { userId, profile: 'data' }; } const memoizedOp = memoize(expensiveOp, { name: 'expensiveOp', ttl: 60000 }); (async () => { let start = Date.now(); let result = await memoizedOp('user1'); console.log('First call took', Date.now() - start, 'ms'); start = Date.now(); result = await memoizedOp('user1'); console.log('Cached call took', Date.now() - start, 'ms'); })();
Debug
Known issues
gotchaOptions 'name' is required; if not provided, the function throws.
fix
Ensure options.name is a string.
affects: >=1.0.0
deprecatedThe callback-based API (v0.x) is not supported in v1.
fix
Use async/await or promises. For callbacks, use v0.x.
affects: >=1.0.0
gotchaThe module does not handle Redis connection errors; client errors may crash the process.
fix
Attach error handler to Redis client: redisClient.on('error', err => console.error(err)).
affects: >=1.0.0
gotchaMemoized function resolves with the cached value from Redis, which may be outdated beyond TTL.
fix
Use a shorter TTL or invalidate cache manually if strict freshness is needed.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: memoize is not a function
Using import { memoize } instead of the default export.
fix
Use default import: import memoize from 'redis-memoizer' or const memoize = require('redis-memoizer').
Error: name option is required
Calling memoize without providing a name in options.
fix
Add name property to options object: memoize(fn, { name: 'myFunction' }).
TypeError: fn must be a function that returns a promise
Passing a callback-style function or non-async function.
fix
Wrap callback in a promise or use async/await.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies
redisrequiredRedis client used for cache store
Agent activity
21 hits · last 30 days
node
18
OpenAI (training)
1
Resources
redis-memoizer — npm install redis-memoizer · libregistry