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.

16 lines (15 loc) 905 B
import { type KeyLookup, type LockInfo, type OwnershipLookup } from "../../common/backend.js"; import type { RedisCapabilities, RedisConfig } from "../types.js"; /** Redis client with eval() and optional function commands */ interface RedisWithCommands { eval(script: string, numKeys: number, ...args: (string | number)[]): Promise<unknown>; getLockInfoByKey?(lockKey: string, toleranceMs: string): Promise<string | null>; getLockInfoByLockId?(lockIdKey: string, lockId: string, toleranceMs: string): Promise<string | null>; } /** * Creates lookup operation for Redis backend. * @returns Async function that retrieves lock info by key or lockId * @see ../scripts.ts for Lua script implementations */ export declare function createLookupOperation(redis: RedisWithCommands, config: RedisConfig): (opts: KeyLookup | OwnershipLookup) => Promise<LockInfo<RedisCapabilities> | null>; export {};