Skip to content

basalt / fastify/src / RedisIdempotencyStore

Class: RedisIdempotencyStore ​

Defined in: fastify/src/drivers/redis-idempotency.ts:31

Redis-backed IdempotencyStore — a first response is cached and replayed for repeats with the same key across every instance, and the reservation survives a restart. Inject an ioredis-compatible client:

ts
import Redis from 'ioredis'
idempotencyPlugin({ store: new RedisIdempotencyStore(new Redis(url)) })

Implements ​

Constructors ​

Constructor ​

> new RedisIdempotencyStore(redis, options?): RedisIdempotencyStore

Defined in: fastify/src/drivers/redis-idempotency.ts:35

Parameters ​

redis ​

RedisLike

options? ​

RedisIdempotencyStoreOptions = {}

Returns ​

RedisIdempotencyStore

Methods ​

complete() ​

> complete(key, record): Promise<void>

Defined in: fastify/src/drivers/redis-idempotency.ts:66

Parameters ​

key ​

string

record ​

IdempotencyRecord

Returns ​

Promise<void>

Implementation of ​

IdempotencyStore.complete


get() ​

> get(key): Promise<"pending" | IdempotencyRecord | undefined>

Defined in: fastify/src/drivers/redis-idempotency.ts:51

A completed record, the string 'pending' for an in-flight request, or undefined.

Parameters ​

key ​

string

Returns ​

Promise<"pending" | IdempotencyRecord | undefined>

Implementation of ​

IdempotencyStore.get


release() ​

> release(key): Promise<void>

Defined in: fastify/src/drivers/redis-idempotency.ts:70

Release a reservation so the client can retry (e.g. after a 5xx).

Parameters ​

key ​

string

Returns ​

Promise<void>

Implementation of ​

IdempotencyStore.release


setPending() ​

> setPending(key): Promise<boolean>

Defined in: fastify/src/drivers/redis-idempotency.ts:58

Atomically reserve the key iff it is free. Returns true when this caller won the reservation, false when a record (pending or completed) already exists — the caller must then get() to decide replay vs. conflict. The check-and-set MUST be atomic so two concurrent first-time requests can't both win (Redis SET NX, a single synchronous step in-process).

Parameters ​

key ​

string

Returns ​

Promise<boolean>

Implementation of ​

IdempotencyStore.setPending

Released under the MIT License.