UNPKG

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.

19 lines (18 loc) 892 B
import { type KeyOp } from "../../common/backend.js"; import type { RedisConfig } from "../types.js"; /** * Redis interface supporting both direct eval and cached command wrappers. * @see ../scripts.ts for Lua script definitions */ interface RedisWithCommands { eval(script: string, numKeys: number, ...args: (string | number)[]): Promise<unknown>; /** Cached command wrapper for IS_LOCKED_SCRIPT (ioredis defineCommand) */ checkLock?(lockKey: string, keyPrefix: string, toleranceMs: string, enableCleanup: string): Promise<number>; } /** * Creates isLocked operation using Lua script for atomicity. * Script checks expiration and optionally cleans up with safety guard. * @see ../scripts.ts for IS_LOCKED_SCRIPT implementation */ export declare function createIsLockedOperation(redis: RedisWithCommands, config: RedisConfig): (opts: KeyOp) => Promise<boolean>; export {};