{"id":26608081,"url":"https://github.com/da440dil/js-locker","last_synced_at":"2025-10-23T21:41:20.439Z","repository":{"id":57105332,"uuid":"174813368","full_name":"da440dil/js-locker","owner":"da440dil","description":"Distributed locking on Node.js","archived":false,"fork":false,"pushed_at":"2022-01-04T09:06:16.000Z","size":151,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-17T22:04:54.662Z","etag":null,"topics":["distributed","distributed-lock","distributed-locking","javascript","lock","locking","locks","nodejs","redis","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/da440dil.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-10T11:20:08.000Z","updated_at":"2022-01-04T09:06:19.000Z","dependencies_parsed_at":"2022-08-21T02:30:09.387Z","dependency_job_id":null,"html_url":"https://github.com/da440dil/js-locker","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/da440dil%2Fjs-locker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/da440dil%2Fjs-locker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/da440dil%2Fjs-locker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/da440dil%2Fjs-locker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/da440dil","download_url":"https://codeload.github.com/da440dil/js-locker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245186881,"owners_count":20574553,"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":["distributed","distributed-lock","distributed-locking","javascript","lock","locking","locks","nodejs","redis","typescript"],"created_at":"2025-03-23T23:32:00.755Z","updated_at":"2025-10-23T21:41:15.419Z","avatar_url":"https://github.com/da440dil.png","language":"TypeScript","readme":"# js-locker\n\n[![Build Status](https://travis-ci.com/da440dil/js-locker.svg?branch=master)](https://travis-ci.com/da440dil/js-locker)\n[![Coverage Status](https://coveralls.io/repos/github/da440dil/js-locker/badge.svg?branch=master)](https://coveralls.io/github/da440dil/js-locker?branch=master)\n\nDistributed locking using [Redis](https://redis.io/).\n\nSupported Redis clients: [node-redis](https://github.com/NodeRedis/node-redis) v3 and v4, [ioredis](https://github.com/luin/ioredis) v4.\n\n[Example](./examples/example.ts) usage with [node-redis](https://github.com/NodeRedis/node-redis) v4:\n\n```typescript\nimport { createClient } from 'redis';\nimport { createLocker } from '@da440dil/js-locker';\n\nasync function main() {\n\tconst client = createClient();\n\tawait client.connect();\n\n\t// Create new locker.\n\tconst locker = createLocker(client);\n\n\t// Try to apply lock.\n\tconst lock = await locker.lock('some-key', 1000);\n\tif (!lock.ok) {\n\t\tconsole.log('Failed to apply lock, retry after %dms', lock.ttl);\n\t\treturn client.quit();\n\t}\n\tconsole.log('Lock applied');\n\n\t// some code here\n\n\t// Optionally try to extend lock.\n\tconst result = await lock.lock(1000);\n\tif (!result.ok) {\n\t\tconsole.log('Failed to extend lock, retry after %dms', result.ttl);\n\t\treturn client.quit();\n\t}\n\tconsole.log('Lock extended');\n\n\t// Try to release lock.\n\tconst ok = await lock.unlock();\n\tif (!ok) {\n\t\tconsole.log('Failed to release lock');\n\t\treturn client.quit();\n\t}\n\tconsole.log('Lock released');\n\n\tawait client.quit();\n}\n\nmain().catch((err) =\u003e {\n\tconsole.error(err);\n\tprocess.exit(1);\n});\n```\n\n```\nnpm run file examples/example.ts\n```\n\n[Benchmarks](./benchmarks)\n```\nnpm run file benchmarks/benchmark.ts\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fda440dil%2Fjs-locker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fda440dil%2Fjs-locker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fda440dil%2Fjs-locker/lists"}