# `Vdr.RedisStream.Callback`
[🔗](https://github.com/savonarola/veidrodelis/blob/v0.1.6/lib/veidrodelis/redis_stream/callback.ex#L1)

Callback module for the Redis stream replica.

You may implement this callback module to make your own handling of commands
replicated from a Redis/Valkey instance.

# `message`

```elixir
@type message() :: term()
```

The message from the callback module.

# `opts`

```elixir
@type opts() :: keyword()
```

The options passed by user to the callback module when starting the replica.

# `reply`

```elixir
@type reply() :: term()
```

The reply from the callback module.

# `state`

```elixir
@type state() :: term()
```

The state of the callback module.

# `handle_call`

```elixir
@callback handle_call(state(), message()) ::
  {:reply, reply(), state()} | {:noreply, state()} | {:error, term()}
```

Handles `&Vdr.RedisStream.Replica.call/2` calls.

# `handle_commands`

```elixir
@callback handle_commands(
  state(),
  [Vdr.RedisStream.ReplicaCommand.t()]
) :: {:ok, state()} | {:error, term()}
```

Called when the replica has received and handled a batch of commands from the Redis.
RDB snapshot and online commands are both handled by this callback.

RDB snapshot data is converted to corresponding ReplicaCommand structs.
For example, if the RDB snapshot contains a list of ["a", "b", "c"] under "l" in database 0,
it will be passed as RPUSH command to the callback:
```elixir
%Vdr.RedisStream.ReplicaCommand{
  db: 0,
  command: {:rpush, "l", ["a", "b", "c"]},
  ...
}
```

# `handle_destroy`

```elixir
@callback handle_destroy(state()) :: :ok | {:error, term()}
```

Called when the replica is about to shutdown (in `&Vdr.RedisStream.Replica.terminate/2`).

# `handle_info`

```elixir
@callback handle_info(state(), message()) :: {:noreply, state()} | {:error, term()}
```

Handles generic messages sent to the replica process which
the replica process has not handled itself.

# `handle_replication_start`

```elixir
@callback handle_replication_start(state()) :: {:ok, state()} | {:error, term()}
```

Called when the replica has established a connection to the Redis
and is about to start replicating.

# `handle_streaming_start`

```elixir
@callback handle_streaming_start(state()) :: {:ok, state()} | {:error, term()}
```

Called when the replica has read and handle the RDB snapshot from the Redis
and starts to stream online commands.

# `init`

```elixir
@callback init(opts()) :: {:ok, state()} | {:error, term()}
```

Called when the replica is started.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
