ExredisPoolboy
This package is basically a wrapper around exredis with poolboy. The main goal was to be able to use all Exredis.Api functions which automatically use workers from the worker pool.
Installation
If available in Hex, the package can be installed as:
- Add
exredis_poolboyto your list of dependencies inmix.exs:
```elixir
def deps do
[{:exredis_poolboy, "~> 0.2.0"}]
end
```
- Ensure
exredis_poolboyis started before your application:
```elixir
def application do
[applications: [:exredis_poolboy]]
end
```
Usage
- Add
ExredisPoolboy.PoolSupervisorto your supervision tree and provide application config key as an argument:
children = [
supervisor(ExredisPoolboy.PoolSupervisor, [config_key: :my_app_redis])
]
- Create a module for using the exredis functions:
defmodule MyApp.Redis do
use ExredisPoolboy.FunctionsDefinitions, :my_app_redis
end
- Add config:
# The fields for redis matches the exredis configuration
config :my_app_redis, :redis,
host: "redis",
port: 6379,
password: "",
db: 0,
reconnect: :no_reconnect,
max_queue: :infinity
# Any name works here, used to create different connection pools if needed
config :my_app_redis, :pool_name, :my_app_redis_pool
# Optional, defaults to 10
config :my_app_redis, :pool, 20
- Use just like you would use exredis:
MyApp.Redis.llen("key")
MyApp.Redis.sadd("key", "value")
Overriding functions
All functions are marked as overridable so you can extend basic functions, for example:
defmodule MyApp.Redis do
use ExredisPoolboy.FunctionsDefinitions, :my_app_redis
def llen(key) do
key
|> super()
|> String.to_integer()
end
end