{"id":14977770,"url":"https://github.com/thiamsantos/red_mutex","last_synced_at":"2025-10-28T05:30:59.294Z","repository":{"id":54515769,"uuid":"174574526","full_name":"thiamsantos/red_mutex","owner":"thiamsantos","description":"Redlock (Redis Distributed Lock) implementation","archived":false,"fork":false,"pushed_at":"2021-02-16T22:47:26.000Z","size":52,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-01T12:11:10.279Z","etag":null,"topics":["elixir","mutex","redis","redlock"],"latest_commit_sha":null,"homepage":"https://hex.pm/packages/red_mutex","language":"Elixir","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/thiamsantos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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-08T16:50:28.000Z","updated_at":"2021-02-16T22:47:28.000Z","dependencies_parsed_at":"2022-08-13T18:20:47.239Z","dependency_job_id":null,"html_url":"https://github.com/thiamsantos/red_mutex","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiamsantos%2Fred_mutex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiamsantos%2Fred_mutex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiamsantos%2Fred_mutex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiamsantos%2Fred_mutex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thiamsantos","download_url":"https://codeload.github.com/thiamsantos/red_mutex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238603665,"owners_count":19499488,"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":["elixir","mutex","redis","redlock"],"created_at":"2024-09-24T13:56:18.447Z","updated_at":"2025-10-28T05:30:59.024Z","avatar_url":"https://github.com/thiamsantos.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RedMutex\n\n\u003c!-- MDOC !--\u003e\n\nRedMutex defines an easy to use interface to control an [distributed lock backed by redis](https://redis.io/topics/distlock).\n\n[![Hex.pm Version](http://img.shields.io/hexpm/v/red_mutex.svg?style=flat)](https://hex.pm/packages/red_mutex)\n[![CI](https://github.com/thiamsantos/red_mutex/workflows/CI/badge.svg?branch=master)](https://github.com/thiamsantos/red_mutex/actions)\n[![Coverage Status](https://coveralls.io/repos/github/thiamsantos/red_mutex/badge.svg?branch=master)](https://coveralls.io/github/thiamsantos/red_mutex?branch=master)\n\n## Usage\n\nWhen used, the mutex expects the :otp_app as option.\nThe :otp_app should point to an OTP application that has the mutex configuration.\nFor example, the mutex:\n\n```elixir\ndefmodule MyApp.MyMutex do\n  use RedMutex, otp_app: :my_app\nend\n```\n\nCould be configured with:\n\n```elixir\nconfig :my_app, MyApp.MyMutex,\n  url: \"redis://localhost:6379\",\n  key: \"red_mutex_lock\",\n  expiration_in_seconds: 3_600\n```\n\nOptions:\n\n  * `:url` - the redis url. Required.\n  * `:key`- The key at redis used to store the lock information.\n    Defaults to `\"red_mutex_lock\"`.\n  * `:expiration_in_seconds` - Time in seconds that the resource will be kept locked.\n    After that time the lock will be automattically released.\n    Defaults to `3600`, one hour.\n\n### Example\n\n```elixir\n# In your config/config.exs file\nconfig :my_app, MyApp.MyMutex,\n  url: \"redis://localhost:6379\",\n  key: \"red_mutex_lock\",\n  expiration_in_seconds: 3_600\n\n# In your application code\ndefmodule MyApp.MyMutex do\n  use RedMutex, otp_app: :my_app\nend\n\ndefmodule MyApp do\n  import RedMutex, only: [synchronize: 1]\n  alias MyApp.MyMutex\n\n  def syncronized_work do\n    synchronize({__MODULE__, :work, []})\n  end\n\n  def lock_unlock do\n    case MyMutex.acquire_lock() do\n      {:ok, lock} -\u003e\n        work()\n        MyMutex.release_lock(lock)\n\n      {:error, reason} -\u003e {:error, reason}\n    end\n  end\n\n  def work do\n    # do some work\n    {:ok, \"completed\"}\n  end\nend\n```\n\n\u003c!-- MDOC !--\u003e\n\n## Installation\n\nThe package can be installed\nby adding `red_mutex` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:red_mutex, \"~\u003e 0.3.0\"}\n  ]\nend\n```\n\nThe docs can be found at [https://hexdocs.pm/red_mutex](https://hexdocs.pm/red_mutex).\n\n## Contributing\n\nSee the [contributing file](CONTRIBUTING.md).\n\n## License\n\n[Apache License, Version 2.0](LICENSE) © [Thiago Santos](https://github.com/thiamsantos)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthiamsantos%2Fred_mutex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthiamsantos%2Fred_mutex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthiamsantos%2Fred_mutex/lists"}