@idempotix/redis
v1.0.2
Published
Redis storage adapter for Idempotix idempotency - works with ioredis
Downloads
8
Maintainers
Readme
@idempotix/redis
Redis storage adapter for Idempotix using ioredis.
Installation
npm install @idempotix/core @idempotix/redis ioredisQuick Start
import { redis } from '@idempotix/redis';
import { express as idempotent } from '@idempotix/express';
// From environment variable (IDEMPOTIX_REDIS_URL)
app.post('/orders', idempotent({ storage: redis() }), handler);Configuration
import { redis } from '@idempotix/redis';
// From environment variable
const storage = redis();
// From URL (password in URL)
const storage = redis('redis://:password@localhost:6379');
// With options
const storage = redis({
url: 'redis://localhost:6379',
keyPrefix: 'myapp:idem:',
});
// With existing ioredis client
import Redis from 'ioredis';
const client = new Redis({ host: 'localhost', password: 'secret' });
const storage = redis({ client });Environment Variables
| Variable | Description |
| --------------------- | ---------------------------------------------------------- |
| IDEMPOTIX_REDIS_URL | Redis connection URL (e.g., redis://:password@host:6379) |
Redis Cluster
import Redis from 'ioredis';
import { redis } from '@idempotix/redis';
const cluster = new Redis.Cluster([
{ host: 'node1.example.com', port: 6379 },
{ host: 'node2.example.com', port: 6379 },
]);
const storage = redis({ client: cluster });AWS ElastiCache
const storage = redis('redis://your-cluster.cache.amazonaws.com:6379');Usage with Express
import { express as idempotent, configure } from '@idempotix/express';
import { redis } from '@idempotix/redis';
const idempotent = configure({
storage: redis(),
ttl: '1h',
});
app.post('/orders', idempotent(), orderHandler);
app.post('/payments', idempotent({ required: true }), paymentHandler);Usage with Next.js
import { next } from '@idempotix/next';
import { redis } from '@idempotix/redis';
export const POST = next({ storage: redis() })(handler);Key Prefix
All keys are prefixed with Idempotix: by default. Customize with:
const storage = redis({ keyPrefix: 'myapp:idem:' });License
MIT
