gudlock
Summary
Add centralised lock support in NodeJS. Underneath, its a simple lock system using TCP communication. Also on Promise. Good luck!
This made to tackles:
- I can't f$%W! (frankly) use Redis
- Race condition in concurrent running async tasks
- Wild access to a resource from multiple node processes
- Yeah those kind of things
Installation
Install gudlock
using the npm package manager:
$ npm install gudlock
User Guide
After deciding up how lock-server is run, using locks is as simple as these:
import { client as gudlock } from 'gudlock'
gudlock.attach({ port: 8827, host: '127.0.0.1' })
const release = await gudlock.lock()
console.log('important processing is running...')
await release()
Its also possible to give the locks name, so its possible to have >1 lock active in the same time, example:
const release = await gudlock.lock('LOCK_NAME_HERE')
console.log('important processing is running...')
await release()
Setting up Lock-Server
This will add package called gudlock
in your project. There are two options on using this package depending on where you want to run the locks-server:
- Run server inside a node app
- Run server as separate node app
1. Running server in node app
This method will attach server to process & runtime of another node app (parent app).
PROS: Generally lighter resources consumption. CONS: Lock service will dies when parent node go down.
How to use this method:
import { server } from 'gudlock'
server.start({ port: 8827, host: '127.0.0.1' })
console.log(`Lock server running on 127.0.0.1:8827`)
2. Running server as separate node process
This method will start server as individual process & runtime.
PROS: Lock service wont depend on any other node app's state. CONS: Generally bigger resources consumption.
How to use this method:
$ node node_modules/gudlock/bin/server
$ node node_modules/gudlock/bin/server --port=7676 --host=128.23.12.3
Contributing
Documentation is an OPEN Open Source Project. This means that:
Individuals making significant and valuable contributions are given
commit-access to the project to contribute as they see fit.