Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ered an application with its own supervision tree #41

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
31 changes: 18 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,40 @@ Usage by example
----------------

```Erlang
1> {ok, Pid} = ered:start_link([{"localhost", 6379}], []).
1> {ok, _} = application:ensure_all_started(ered, temporary),
2> {ok, Pid} = ered:connect_cluster([{"localhost", 6379}], []).
{ok,<0.164.0>}
2> ered:command(Pid, [<<"SET">>, <<"mykey">>, <<"42">>], <<"mykey">>, 5000).
3> ered:command(Pid, [<<"SET">>, <<"mykey">>, <<"42">>], <<"mykey">>, 5000).
{ok,<<"OK">>}
3> ered:command_async(Pid, [<<"GET">>, <<"mykey">>], <<"mykey">>, fun(Reply) -> io:format("Reply: ~p~n", [Reply]) end).
4> ered:command_async(Pid, [<<"GET">>, <<"mykey">>], <<"mykey">>, fun(Reply) -> io:format("Reply: ~p~n", [Reply]) end).
ok
Reply: {ok,<<"42">>}
4> ered:stop(Pid).
5> ered:stop(Pid).
zuiderkwast marked this conversation as resolved.
Show resolved Hide resolved
ok
```

Functions
---------

### `start_link/2`
### `connect_cluster/2`

```Erlang
start_link([addr()], [opt()]) -> {ok, server_ref()} | {error, term()}.
connect_cluster([addr()], [opt()]) -> {ok, server_ref()} | {error, term()}.
```

Start the main process. This will also start the cluster handling
process which will set up clients to the provided addresses and
fetch the cluster slot map. Once there is a complete slot map and
all Redis node clients are connected this process is ready to
serve requests.
serve requests. The processes are supervised by the `ered` application,
which needs to be started in advance.

One or more addresses, `addr() :: {inet:socket_address() | inet:hostname(),
inet:port_number()}`, is used to discover the rest of the cluster.
inet:port_number()}`, are used to discover the rest of the cluster.

For options, see [Options](#options) below.

### `stop/1`
### `close/1`

```Erlang
stop(server_ref()) -> ok.
zuiderkwast marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -145,7 +147,7 @@ used.
Options
-------

The following options can be passed to `start_link/2`:
The following options can be passed to `connect/2`:
zuiderkwast marked this conversation as resolved.
Show resolved Hide resolved

* `{try_again_delay, non_neg_integer()}`

Expand Down Expand Up @@ -187,7 +189,7 @@ The following options can be passed to `start_link/2`:

### Client options

Options passed to `start_link/2` as the options `{client_opts, [...]}`.
Options passed to `connect/2` as the options `{client_opts, [...]}`.
zuiderkwast marked this conversation as resolved.
Show resolved Hide resolved

* `{connection_opts, [ered_connection:opt()]}`

Expand Down Expand Up @@ -242,7 +244,7 @@ Options passed to `start_link/2` as the options `{client_opts, [...]}`.

### Connection options

Options passed to `start_link/2` as the options `{client_opts, [{connection_opts, [...]}]}`.
Options passed to `connect/2` as the options `{client_opts, [{connection_opts, [...]}]}`.

* `{batch_size, non_neg_integer()}`

Expand Down Expand Up @@ -281,7 +283,7 @@ Info messages
-------------

When one or more pids have been provided as the option `{info_pid, [pid()]}` to
`start_link/2`, these are the messages ered sends. All messages are maps with at
`connect/2`, these are the messages ered sends. All messages are maps with at
least the key `msg_type`.

Messages about the cluster as a whole:
Expand Down Expand Up @@ -316,6 +318,9 @@ Messages about the cluster as a whole:
mapping. The `response` is either an error or the atom `empty` if the CLUSTER
SLOTS returned an empty list, which is treated like an error.

* `#{msg_type := cluster_stopped, reason := any()}` when the ered cluster
instance is closing down.

Messages about the connection to a specific node are in the following form:

```Erlang
Expand Down
2 changes: 1 addition & 1 deletion src/ered.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
ssl]},
{env,[]},
{modules, []},

{mod, {ered_app, []}},
{licenses, ["MIT"]},
{links, []}
]}.
Loading
Loading