express-idempotency-redis-adapter
raw JSON → 1.0.8 verified Fri May 01 auth: no javascript
Redis adapter for the express-idempotency middleware, enabling idempotency key storage in Redis. v1.0.8, stable, low update cadence. Key differentiator: integrates seamlessly with express-idempotency middleware and supports both connection config and existing Redis instances, with configurable TTL. Alternatives require custom Redis integration.
Common errors
error Error: RedisAdapter requires either connectionConfig or connectionInstance ↓
cause Missing either option when instantiating the adapter.
fix
Pass connectionConfig (object with url) or connectionInstance (existing node-redis client).
error TypeError: adapter.connect is not a function ↓
cause Importing default incorrectly (non-function object).
fix
import RedisAdapter from 'express-idempotency-redis-adapter' (default export).
error Error: connect ECONNREFUSED ::1:6379 ↓
cause Redis server not running or wrong host/port.
fix
Ensure Redis is running, or set REDIS_URL environment variable.
error Error: The dataAdapter provided does not implement the required interface. ↓
cause Passing something that is not a RedisAdapter instance.
fix
Use new RedisAdapter(options) and pass the instance.
Warnings
gotcha You must provide either connectionConfig or connectionInstance, not both. ↓
fix Pass only one of the two options.
gotcha The adapter.connect() must be called before using the middleware. ↓
fix Ensure async connect() is awaited before app.use().
gotcha TTL option is in seconds; default is 86400 (1 day). ↓
fix Set ttl to your desired value in seconds.
gotcha The adapter does not support Redis Cluster or Sentinel out of the box. ↓
fix Use connectionInstance with a pre-configured ioredis client if needed.
Install
npm install express-idempotency-redis-adapter yarn add express-idempotency-redis-adapter pnpm add express-idempotency-redis-adapter Imports
- RedisAdapter (default) wrong
const RedisAdapter = require('express-idempotency-redis-adapter')correctimport RedisAdapter from 'express-idempotency-redis-adapter' - RedisAdapter (named)
import { RedisAdapter } from 'express-idempotency-redis-adapter' - types (TypeScript)
import type { RedisAdapterOptions } from 'express-idempotency-redis-adapter'
Quickstart
import idempotency from 'express-idempotency';
import RedisAdapter from 'express-idempotency-redis-adapter';
import express from 'express';
const app = express();
const adapter = new RedisAdapter({
connectionConfig: { url: process.env.REDIS_URL ?? 'redis://localhost:6379' },
ttl: 3600
});
await adapter.connect();
app.use(idempotency({
dataAdapter: adapter
}));
app.listen(3000, () => console.log('Server running'));