forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redlock.d.ts
62 lines (44 loc) · 1.62 KB
/
redlock.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Type definitions for Redlock
// Project: https://github.com/mike-marcacci/node-redlock
// Definitions by: Ilya Mochalov <https://github.com/chrootsu>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../bluebird/bluebird.d.ts" />
declare module RedlockTypes {
interface LockError extends Error {}
interface NodeifyCallback<T> {
(err: any, value?: T): void;
}
interface Lock {
redlock: Redlock;
resource: string;
value: any;
expiration: number;
unlock(callback?: NodeifyCallback<void>): Promise<void>;
extend(ttl: number, callback?: NodeifyCallback<Lock>): Promise<Lock>;
}
interface RedlockOptions {
driftFactor?: number;
retryCount?: number;
retryDelay?: number;
}
class Redlock {
LockError: LockError;
driftFactor: number;
retryCount: number;
retryDelay: number;
servers: any[]; // array of redis.RedisClient
constructor(clients: any[], options?: RedlockOptions);
acquire(resource: string, ttl: number, callback?: NodeifyCallback<Lock>): Promise<Lock>;
lock(resource: string, ttl: number, callback?: NodeifyCallback<Lock>): Promise<Lock>;
disposer(resource: string, ttl: number): any; // return bluebird.Disposer
release(lock: Lock, callback?: NodeifyCallback<void>): Promise<void>;
unlock(lock: Lock, callback?: NodeifyCallback<void>): Promise<void>;
extend(lock: Lock, ttl: number, callback?: NodeifyCallback<Lock>): Promise<Lock>;
_lock(resource: string, value: string, ttl: number, callback?: NodeifyCallback<Lock>): Promise<Lock>;
_random(): string;
}
}
declare module "redlock" {
import Redlock = RedlockTypes.Redlock;
export = Redlock;
}