UNPKG

@jbagatta/johnny-locke

Version:

A robust, strongly-consistent distributed locking library that provides atomic operations across multiple processes

24 lines (23 loc) 1.08 kB
import Redis from 'ioredis'; import { LockConfiguration, IDistributedLock, Readable, Writable } from '../types'; export declare class RedisDistributedLock implements IDistributedLock { private readonly redis; private readonly config; private readonly lockListener; private active; private constructor(); static create(redis: Redis, config: LockConfiguration): Promise<IDistributedLock>; withLock<T>(key: string, timeoutMs: number, callback: (state: T | null) => Promise<T>, lockDuration?: number): Promise<Readable<T>>; acquireLock<T>(key: string, timeoutMs: number, lockDuration?: number): Promise<Writable<T>>; tryAcquireLock<T>(key: string, lockDuration?: number): Promise<{ acquired: boolean; value: Writable<T> | undefined; }>; private getOrCreateLock; releaseLock<T>(key: string, lockObj: Writable<T>): Promise<boolean>; wait<T>(key: string, timeoutMs: number): Promise<Readable<T>>; delete(key: string): Promise<boolean>; close(): void; private toNamespacedKey; private checkActive; }