RedisMutex is a library for creating a Redis lock for a single Redis instance.
From Hex, the package can be installed as:
- Add
redis_mutexto your list of dependencies inmix.exs:
def deps do
[{:redis_mutex, "~> 0.1.0"}]
end- Ensure
redis_mutexis started before your application:
def application do
[applications: [:redis_mutex]]
end- Set the
redis_urlin yourconfig.exs
config :redis_mutex, redis_url: {:system, "REDIS_URL"}- Call
use RedisMutexin the module you want to use the lock and usewith_lockto lock critical parts of your code.
defmodule PossumLodge do
use RedisMutex
def get_oauth do
with_lock("my_key") do
"Quando omni flunkus moritati"
end
end
end