UNPKG

1.04 kBMarkdownView Raw
1# RedLock #
2
3Distributed locking mechanism with lock names, timeouts and keep-alive.
4
5## Example ##
6
7```javascript
8var redlock = require('redlock');
9
10var getLock = redlock({
11 client : redisClient,
12 prefix : 'lock:',
13 timeout : 120,
14});
15
16getLock('mylock', function(err, lock) {
17 // if there's been a bad error, get out of here
18 if (err) throw err;
19
20 // if we didn't get the lock, just return
21 if ( !lock ) return;
22
23 doSomethingInvolvingAsyn(function(err) {
24 // we've now finished with the lock
25 lock.release();
26 });
27});
28```
29
30## Options to 'redlock' ##
31
32* client
33* prefix (default: '')
34* timeout (default: 60)
35
36## Options to 'getLock' ##
37
38* name (required)
39* timeout (optional)
40* callback (required)
41
42If you provide a timeout, it will be
43
44
45# Author #
46
47Written by [Andrew Chilton](http://chilts.org/) - [Blog](http://chilts.org/blog/) -
48[Twitter](https://twitter.com/andychilton).
49
50# License #
51
52* [Copyright 2013 Andrew Chilton. All rights reserved.](http://chilts.mit-license.org/2013/)
53
54(Ends)