{"id":16981985,"url":"https://github.com/1602/lock-inc","last_synced_at":"2025-03-21T23:41:00.127Z","repository":{"id":138876076,"uuid":"54192348","full_name":"1602/lock-inc","owner":"1602","description":null,"archived":false,"fork":false,"pushed_at":"2016-07-10T11:45:29.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-26T18:13:23.479Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/1602.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-03-18T10:12:39.000Z","updated_at":"2016-03-18T10:12:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"175101b7-2408-48a2-a5bf-93ef5cff59ba","html_url":"https://github.com/1602/lock-inc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1602%2Flock-inc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1602%2Flock-inc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1602%2Flock-inc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1602%2Flock-inc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/1602","download_url":"https://codeload.github.com/1602/lock-inc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244885515,"owners_count":20526293,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T02:07:00.489Z","updated_at":"2025-03-21T23:41:00.118Z","avatar_url":"https://github.com/1602.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Optimistic locking library\n\n[![Coverage Status](https://coveralls.io/repos/github/1602/lock-inc/badge.svg?branch=master)](https://coveralls.io/github/1602/lock-inc?branch=master)\n\nIt uses redis `INCR` command to obtain lock of resource. Logic is dead simple - if\nredis returns 1 - we got lock if it returns more than 2 it will throw\n`Resource locked` error.\n\n## Installation\n\n    npm install lock-inc\n\n## Usage\n\n```\nconst lockFactory = require('lock-inc');\nconst locker = lockFactory({\n    driver: 'redis',\n    // for all possible config: object keys see https://github.com/NodeRedis/node_redis#options-is-an-object-with-the-following-possible-properties\n    config: {\n    \thost: 'localhost',\n\tport: 6379,\n\tdb: 1\n    },\n    settings: {\n    \tprefix: 'lock:'\n    }\n});\n\n// simple locking\nlocker.lock('User:1602')\n    .then(lock =\u003e {\n    \treturn doSomethingAsync()\n\t    .then(lock.unlock);\n    });\n\n// unlock by timeout (uses redis EXPIRE command)\nlocker.lock('User:1603', {expire: 1}) // lock will expire in 1 second\n    .then(lock =\u003e {\n    \tdoJob();\n    \tlock.unlock(); // it is safe to not call it at all\n    });\n\n// to remove all existing locks\nlocker.purge()\n    .then(() =\u003e console.log('All locks removed'));\n```\n\n## MIT License\n\n    Copyright (C) 2011 by Anatoliy Chakkaev \u003cmail [åt] anatoliy [døt] in\u003e\n\n    Permission is hereby granted, free of charge, to any person obtaining a copy\n    of this software and associated documentation files (the \"Software\"), to deal\n    in the Software without restriction, including without limitation the rights\n    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n    copies of the Software, and to permit persons to whom the Software is\n    furnished to do so, subject to the following conditions:\n\n    The above copyright notice and this permission notice shall be included in\n    all copies or substantial portions of the Software.\n\n    THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n    THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1602%2Flock-inc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F1602%2Flock-inc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1602%2Flock-inc/lists"}