RedisMutex
RedisMutex is a library for creating a Redis lock for a single Redis instance.
Installation
The package can be installed by adding redis_mutex
to your list of dependencies in mix.exs:
def deps do
[
{:redis_mutex, "~> 0.4.0"}
]
end
Usage
- 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
Tests
To run the portion of the test suite that does not rely on Redis, run the default command:
mix test
To run the full test suite including those portions that depend on a Redis instance running
and being configured in config/test.exs, run the following command:
REDIS_TESTS=true mix test --include=redis_dependent