idempotency-redis
Version:
Idempotency guarantee via Redis
30 lines (29 loc) • 911 B
TypeScript
import Client from 'ioredis';
export type CachedResult = {
type: 'error';
error: string;
} | {
type: 'value';
value?: string;
};
export declare class RedisCache {
private readonly redis;
/**
* Constructs an instance of RedisCache.
* @param redis A RedisClientType instance for Redis operations.
*/
constructor(redis: Client);
/**
* Retrieves a cached result by key.
* @param key The cache key to retrieve the value for.
* @returns A promise that resolves to a CachedResult or null if the key is not found.
*/
get(key: string): Promise<CachedResult | null>;
/**
* Sets a value in the cache.
* @param key The cache key to set the value for.
* @param value The CachedResult to store.
* @returns A promise that resolves when the operation is complete.
*/
set(key: string, value: CachedResult): Promise<void>;
}