Vdr.RedisStream.Callback behaviour (veidrodelis v0.1.6)

Copy Markdown View Source

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.

Summary

Types

The message from the callback module.

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

The reply from the callback module.

The state of the callback module.

Callbacks

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

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.

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

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

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

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

Called when the replica is started.

Types

message()

@type message() :: term()

The message from the callback module.

opts()

@type opts() :: keyword()

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

reply()

@type reply() :: term()

The reply from the callback module.

state()

@type state() :: term()

The state of the callback module.

Callbacks

handle_call(state, message)

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

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

handle_commands(state, list)

@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:

%Vdr.RedisStream.ReplicaCommand{
  db: 0,
  command: {:rpush, "l", ["a", "b", "c"]},
  ...
}

handle_destroy(state)

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

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

handle_info(state, message)

@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(state)

@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(state)

@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(opts)

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

Called when the replica is started.