{"id":27786331,"url":"https://github.com/clever/node-redis-reservation","last_synced_at":"2025-04-30T15:59:46.612Z","repository":{"id":42634637,"uuid":"13077804","full_name":"Clever/node-redis-reservation","owner":"Clever","description":"Distributed locking mechanism built on redis.","archived":false,"fork":false,"pushed_at":"2024-09-23T15:44:39.000Z","size":51,"stargazers_count":5,"open_issues_count":3,"forks_count":1,"subscribers_count":64,"default_branch":"master","last_synced_at":"2025-03-17T16:53:17.923Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"CoffeeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Clever.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":"2013-09-24T22:07:14.000Z","updated_at":"2024-09-23T15:44:43.000Z","dependencies_parsed_at":"2023-01-31T20:45:16.041Z","dependency_job_id":null,"html_url":"https://github.com/Clever/node-redis-reservation","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clever%2Fnode-redis-reservation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clever%2Fnode-redis-reservation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clever%2Fnode-redis-reservation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clever%2Fnode-redis-reservation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Clever","download_url":"https://codeload.github.com/Clever/node-redis-reservation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251737982,"owners_count":21635714,"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":"2025-04-30T15:59:43.250Z","updated_at":"2025-04-30T15:59:46.603Z","avatar_url":"https://github.com/Clever.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"node-redis-reservation\n======================\n\nredis reservations are like locks/mutexes except they can expire.\n\n### constructor(by, host, port, heartbeat_interval, lock_ttl, log, password)\n\nCreates a new redis-reservation which includes setting up redis connection credentials.\n\n##### Arguments\n- `by` - The worker name\n- `host` - Redis host to connect to\n- `port` - Redis port to connect to\n- `heartbeat_interval` - Renew the lock at every `heartbeat_interval` milliseconds\n- `lock_ttl` - Renew the lock for `lock_ttl` seconds\n- `log` - Log to use or else defaults to console.log\n- `password` - Password to authenticate with redis server\n\n##### Example\n```\nReserveResource = require 'redis-reservation'\n\nreservation = new ReserveResource\n  'worker-name',\n  process.env.REDIS_HOST,\n  process.env.REDIS_PORT,\n  10 * 60 * 1000,           # 10 minutes\n  30 * 60                   # 30 minutes\n  # log,                     # defaults to console.log\n  # password                # defaults to no password (empty string)\n```\n\n----\n### lock(resource, callback)\n\nAttempts to lock the resource if it can.\n\n##### Arguments\n- `resource` - The key to use to uniquely identify this lock\n- `callback(err, lock_status)` - `lock_status` is `true` if lock was acquired, `false` otherwise.\n\n##### Example\n```\nreservation.lock job_name, (err, lock_status) -\u003e\n  return err if err?\n  if lock_status\n    do_job()\n  else\n    console.log 'Reservation already held'\n```\n\n----\n### wait_until_lock(resource, callback)\nWaits until the lock can be acquired for the resource.\n\n##### Arguments\n- `resource` - The key to use to uniquely identify this lock\n- `callback(err, reserve_key)` - `callback` is called only when the lock can be acquired. `reserve_key` is the name of the key in redis that was used to acquire the lock.\n\n##### Example\n```\nreservation.wait_until_lock job_name, (err, reserve_key) -\u003e\n  return err if err?\n  do_job()\n```\n\n----\n### release(callback)\nReleases the lock.\n\n##### Arguments\n- `callback(err)` - Callback to be called once the lock is released, or error.\n\n##### Example\n```\nreservation.release (err) -\u003e\n  if err?\n    console.log 'Could not release lock, maybe the reservation was already lost?'\n  return err\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclever%2Fnode-redis-reservation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclever%2Fnode-redis-reservation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclever%2Fnode-redis-reservation/lists"}