syncguard
Version:
Functional TypeScript library for distributed locking across microservices. Prevents race conditions with Redis, PostgreSQL, Firestore, and custom backends. Features automatic lock management, timeout handling, and extensible architecture.
16 lines (15 loc) • 747 B
TypeScript
import { type ExtendResult, type LockOp } from "../../common/backend.js";
import type { RedisConfig } from "../types.js";
/** Redis client with eval and optional cached extendLock method */
interface RedisWithCommands {
eval(script: string, numKeys: number, ...args: (string | number)[]): Promise<unknown>;
extendLock?(lockIdKey: string, lockId: string, toleranceMs: string, ttlMs: string): Promise<[number, number] | number>;
}
/**
* Creates extend operation that atomically renews lock TTL (replaces entirely, not additive).
* @see docs/specs/redis-backend.md
*/
export declare function createExtendOperation(redis: RedisWithCommands, config: RedisConfig): (opts: LockOp & {
ttlMs: number;
}) => Promise<ExtendResult>;
export {};