{"_id":"@42technologies/node-redis-warlock","_rev":"3-c7d8d1770251f407fe4ef3e2cffda2b8","name":"@42technologies/node-redis-warlock","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.1":{"name":"@42technologies/node-redis-warlock","version":"1.0.1","description":"Battle-hardened distributed locking using redis","main":"lib/warlock.js","publishConfig":{"access":"public"},"scripts":{"pretest":"npm run start-redis","posttest":"npm run cleanup","start-redis":"docker-compose up -d redis","test":"mocha --exit ./test/warlock","cleanup":"docker-compose stop && docker-compose rm -f"},"repository":{"type":"git","url":"git+https://github.com/42technologies/warlock.git"},"keywords":["node.js","redis","lock"],"author":{"name":"Geoff Wagstaff"},"license":"MIT","bugs":{"url":"https://github.com/thedeveloper/warlock/issues"},"homepage":"https://github.com/thedeveloper/warlock","dependencies":{"node-redis-script":"^2.0.1","uuid":"^8.3.2"},"devDependencies":{"eslint":"^7.23.0","eslint-config-airbnb-base":"^14.2.1","eslint-plugin-import":"^2.22.1","mocha":"^8.3.2","redis":"^3.1.0","should":"^13.2.3"},"gitHead":"f426f5aaae688ed385f00bb55e9e51782fc5bde6","_id":"@42technologies/node-redis-warlock@1.0.1","_nodeVersion":"16.11.0","_npmVersion":"8.1.1","dist":{"integrity":"sha512-0sGVQtdpvkllRzc/fi/J7uv5O9XX8KpeWlB2xjMFUxuBUzLS4wdVjk8b9f871OB17FHBECDD3E9uX/v1rm91Uw==","shasum":"3f619cd7a896ef3c12d3d318afcc0003804bbae9","tarball":"https://registry.npmjs.org/@42technologies/node-redis-warlock/-/node-redis-warlock-1.0.1.tgz","fileCount":12,"unpackedSize":12673,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhuhjECRA9TVsSAnZWagAAoTQP/AurTLT51MpVRCarI9wF\nHdnLFDaxeUf/hl5sMXAFh+GAMbzdJ1yTSSuVsg6N4W4AZt3V+Q1wDZkiKuyJ\nEreg89pxB6Xx6UXaa5rbKvfim1vvF0tQjDOrP7Z49EehpS6zYXYwW92K9mNq\nO2n2HL5KBP5RlvAsbBLpWpvjuAsMP/02mRlEF5LJsV9MCSLZpl/4XeREWIrT\nqOSkqEqohEmzIhvti1ccCxPKSDKOAOQwWXgSv3KEnir54ztR2jUISjX+vuCd\nPAuTKLjnxVvhRhqUm6dvUYu+7X74rfCxiQhr1pok7y8Ln3Z3k/hy8xEq9iIP\nU85pdA82IQ/slFyF1/JtFo+goAGieuP/TTQYZup3d/itdetKlKudGcP4iDXM\nU4oU+QcPgJh5B1qAlwbOMdvanzk6Fy5/eQxeyADWS1g79MXEsmtD5fZUDly9\nNn6OQqtJjVI8CA9YcQtzaWEhmcZ0+5X7+r3Hgv2BPz6ZAi68EjOMXbTTNgZ4\nOUegM698GSWirs2IuGxVLcnE2FNK0DbEOhlA39lFys//dpUQH8qn7m0UfP6k\nv7zoEH2ZrRF0bsbOTCm1xUzWWOAtGc/bKEG+CPs/rGgmWrBnnf2uoTYvn9Pj\nIC7eCyv4yqGunqGhZrscuKusMHrbAYkMFADKq8rteoY8xy1Jp52Fjs+T5EPa\nJ75c\r\n=sFkX\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCNyM6yrptninP3yySIZkKjJGNKOg2aLLFihAe74d4ZKAIhAKjUz90x+dcQz3bzyPrCzQs3ZAUwbRY69iB2cuIdUDfD"}]},"_npmUser":{"name":"nickporter42","email":"nick@42technologies.com"},"directories":{},"maintainers":[{"name":"surjikal","email":"npm@surj.email"},{"name":"nickporter42","email":"nick@42technologies.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/node-redis-warlock_1.0.1_1635134249726_0.48840911680673615"},"_hasShrinkwrap":false}},"time":{"created":"2021-10-25T03:57:29.683Z","1.0.1":"2021-10-25T03:57:29.850Z","modified":"2022-04-04T10:45:49.843Z"},"maintainers":[{"email":"lars.butzmann@gmail.com","name":"lbutzmann"},{"email":"npm@surj.email","name":"surjikal"},{"email":"nick@42technologies.com","name":"nickporter42"}],"description":"Battle-hardened distributed locking using redis","homepage":"https://github.com/thedeveloper/warlock","keywords":["node.js","redis","lock"],"repository":{"type":"git","url":"git+https://github.com/42technologies/warlock.git"},"author":{"name":"Geoff Wagstaff"},"bugs":{"url":"https://github.com/thedeveloper/warlock/issues"},"license":"MIT","readme":"warlock\n=======\n\n[![Join the chat at https://gitter.im/TheDeveloper/warlock](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/TheDeveloper/warlock?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)\n\nBattle-hardened distributed locking using redis.\n\n## Requirements\n\n* [node-redis](https://github.com/mranney/node_redis) compatible with `v0.10`\n* Redis `v2.6.12` or above. If you're running a Redis version from `v2.6.0` to `v2.6.11` inclusive use `v0.0.7` of this module.\n\n## Install\n\n    npm install node-redis-warlock\n\n## Usage\n\n```javascript\nconst Warlock = require('node-redis-warlock');\nconst Redis = require('redis');\n\n// Establish a redis client and pass it to warlock\nconst redis = Redis.createClient();\nconst warlock = Warlock(redis);\n\n// Set a lock\nconst key = 'test-lock';\nconst ttl = 10000; // Lifetime of the lock\n\nwarlock.lock(key, ttl, (err, unlock) => {\n  if (err) {\n    // Something went wrong and we weren't able to set a lock\n    return;\n  }\n\n  if (typeof unlock === 'function') {\n    // If the lock is set successfully by this process, an unlock function is passed to our callback.\n    // Do the work that required lock protection, and then unlock() when finished...\n    //\n    // do stuff...\n    //\n    unlock();\n  } else {\n    // Otherwise, the lock was not established by us so we must decide what to do\n    // Perhaps wait a bit & retry...\n  }\n});\n\n// set a lock optimistically\nconst key = 'opt-lock';\nconst ttl = 10000;\nconst maxAttempts = 4; // Max number of times to try setting the lock before erroring\nconst wait = 1000; // Time to wait before another attempt if lock already in place\nwarlock.optimistic(key, ttl, maxAttempts, wait, (err, unlock) => {});\n\n// unlock using the lock id\nvar key = 'test-lock-2';\nvar ttl = 10000;\nlet lockId;\n\nwarlock.lock(key, ttl, (err, _, id) => {\n  lockId = id;\n});\n\n// each client who knows the lockId can release the lock\nwarlock.unlock(key, lockId, (err, result) => {\n  if (result == 1) {\n    // unlocked successfully\n  }\n});\n\n// change a lock's ttl\nvar key = 'touch-lock';\nvar ttl = 10000;\nvar ttl2 = 20000;\n\nwarlock.lock(key, ttl, function(err, unlock, id) {\n  warlock.touch(key, id, ttl2, function(err) {});\n});\n```\n\n## ProTips\n\n* Read my [Distributed locks using Redis](https://engineering.gosquared.com/distributed-locks-using-redis) article and Redis' author's [A proposal for more reliable locks using Redis](http://antirez.com/news/77) to learn more about the theory of distributed locks using Redis.\n","readmeFilename":"README.md"}