Flux Redis
Integrate Redis to Elixir projects.
It uses Redix, check their documentation to understand how this library
request commands to Redis.
Usage
Add Flux Redis as a dependency in your
mix.exs file:
def deps do
[{:flux_redis, "~> 0.0.2"}]
endFluxRedis.HashManager describes how to use Redis as json storage.
FluxRedis.PipelineManager describes how to execute multiple commands in a
single request.
Application Configuration
import Config
config :flux_redis,
connection: [
uri: "redis://redis",
timeout: 5_000,
sync_connect: true,
exit_on_disconnection: false,
backoff_initial: 1_000,
backoff_max: 10_000
],
hash_storages: []:connection- Set the Redis connection. Acceptst:keyword/0. Options are::uri- The Redis URI. Acceptst:String.t/0. Defaults toredis://redis. More information att:FluxRedis.redis_uri/0.:timeout- Milliseconds to wait for a connection. Defaults to5_000. Acceptst:integer/0.:sync_connect- Iffalse, it will not hold while starting the child process. Defaults totrue. Acceptst:boolean/0.:exit_on_disconnection- Iftrue, it will exit and trigger error on connection failure. Defaults tofalse. Acceptst:boolean/0.:backoff_initial- Initial milliseconds to wait before reattempting connection. Defaults to1_000. Acceptst:integer/0.:backoff_max- Maximum milliseconds to wait before reattempting connection. The backoff will increase by a ratio of1.5until it reaches the maximum backoff. Defaults to10_000. Acceptst:integer/0.
:hash_storages- Set the JSON storage name and the keyt:atom/0which will generate the redis hash field name. Acceptst:keyword/0. Defaults to emptyt:keyword/0. An example of definition is:hash_storages: [ cars: [:brand, :model], users: :id ]Every key defined in
:hash_storagewill be used with the EXACT sequence to retrieve a JSON element or to create a redis hash field.The hash field name is set by joining the value of each key with
|separator.-
From the example: users hash field names will be defined as
<user_id>and cars hash field names will be defined as<car_brand>|<car_model>.
-
From the example: users hash field names will be defined as