# shardex v0.1.0 - API Reference

## Modules

- [Shardex](Shardex.md): Route keys and batches of items to sharded pools.
- [Shardex.Batch](Shardex.Batch.md): Result of `Shardex.group/4`: items grouped by shard, plus every item that
could not be routed with its reason. Items keep their input order.

- [Shardex.Pool](Shardex.Pool.md): One pool of a shard for a given role. `ref` is what callers receive
(a repo module, a registered name, ...). `meta` is adapter-specific.

- [Shardex.Shard](Shardex.Shard.md): A shard: a routing target with one pool per role (`:primary`, `:replica`, ...).
- [Shardex.Telemetry](Shardex.Telemetry.md): Telemetry events emitted by Shardex. Every event's metadata includes `:instance`.

- Strategies
  - [Shardex.Strategy](Shardex.Strategy.md): Behaviour for routing keys to shard names.
  - [Shardex.Strategy.Cached](Shardex.Strategy.Cached.md): Caches another strategy's results in ETS. Useful for directory strategies
that query a database.
  - [Shardex.Strategy.Hash](Shardex.Strategy.Hash.md): Default strategy: `:erlang.phash2(key, shard_count)` over the configured
shard list. Adding or removing a shard remaps most keys; use
`Shardex.Strategy.JumpHash` if the shard count will grow.

  - [Shardex.Strategy.JumpHash](Shardex.Strategy.JumpHash.md): Jump consistent hash (Lamping & Veach, 2014). Appending a shard to the end of
the shard list moves only ~1/n of the keys, all of them to the new shard.
Always append new shards; reordering or removing shards remaps keys.

  - [Shardex.Strategy.Static](Shardex.Strategy.Static.md): Routes from a fixed map: `{Shardex.Strategy.Static, map: %{key => shard}, default: shard}`.
Without `:default`, unmapped keys are `{:error, :unassigned}`. Handy in tests.

- Adapters
  - [Shardex.Adapter](Shardex.Adapter.md): Behaviour for pool adapters.
  - [Shardex.Adapter.Ecto](Shardex.Adapter.Ecto.md): Adapter for Ecto repos. Requires the optional `:ecto` dependency.
  - [Shardex.Adapter.Generic](Shardex.Adapter.Generic.md): Adapter for any pool: you provide the child spec and the ref.
  - [Shardex.Adapter.Redix](Shardex.Adapter.Redix.md): Adapter for Redis via `Redix`. Requires the optional `:redix` dependency.
  - [Shardex.Adapter.Redix.Pool](Shardex.Adapter.Redix.Pool.md): Ref of a Redix shard pool with `pool_size > 1`: the connection names.

- Exceptions
  - [Shardex.BatchError](Shardex.BatchError.md): Raised by `Shardex.run_batch/5` with `on_error: :raise` when items cannot be routed.
  - [Shardex.Error](Shardex.Error.md): Raised by the bang routing functions (`ref!/3`, `run!/4`).

