Redis.Resilience (Redis v0.7.1)

Copy Markdown View Source

Composable resilience wrapper for Redis connections.

Stacks circuit breaker, retry, coalescing, and bulkhead patterns around a Redis connection. All patterns are optional -- include only what you need.

Requires {:ex_resilience, "~> 0.4"} in your dependencies.

Usage

# Full resilience stack
{:ok, r} = Redis.Resilience.start_link(
  port: 6379,
  retry: [max_attempts: 3, backoff: :exponential],
  circuit_breaker: [failure_threshold: 5, reset_timeout: 5_000],
  coalesce: true,
  bulkhead: [max_concurrent: 50]
)

# Same API as a regular connection
Redis.Resilience.command(r, ["GET", "key"])
Redis.Resilience.pipeline(r, [["GET", "a"], ["GET", "b"]])

# Inspect the stack
Redis.Resilience.info(r)

Composition Order (inside -> outside)

Connection -> Retry -> CircuitBreaker -> Coalesce -> Bulkhead
             ^ retries transient errors
                    ^ fails fast when unhealthy
                                 ^ deduplicates concurrent requests
                                              ^ limits concurrency

Options

Summary

Functions

Returns a specification to start this module under a supervisor.

Executes a Redis command through the resilience stack.

Returns info about the resilience stack.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

command(r, args, opts \\ [])

Executes a Redis command through the resilience stack.

Pipeline calls run in the caller's process so that concurrency-limiting layers (bulkhead) work correctly across concurrent callers.

info(r)

Returns info about the resilience stack.

pipeline(r, commands, opts \\ [])

start_link(opts)

stop(r)

transaction(r, commands, opts \\ [])