Redgrid performs automatic Erlang node discovery through a shared Redis pub/sub channel.
$ make
$ erl -pa ebin deps/*/ebin
1> redgrid:start_link().
{ok,<0.33.0>}
2> whereis(redgrid).
<0.33.0>
$ erl -pa ebin deps/*/ebin
1> redgrid:start_link([{redis_url, "redis://localhost:6379/"}]).
{ok,<0.33.0>}
$ erl -pa ebin deps/*/ebin
1> redgrid:start_link([anonymous]).
{ok,<0.33.0>}
$ erl -pa ebin deps/*/ebin
1> redgrid:start_link([{<<"foo">>, <<"bar">>}]).
{ok,<0.33.0>}
Start foo node
$ erl -pa ebin deps/*/ebin -name foo@`hostname`
([email protected])1> redgrid:start_link().
{ok,<0.39.0>}
Start bar node
$ erl -pa ebin deps/*/ebin -name bar@`hostname`
([email protected])1> redgrid:start_link().
{ok,<0.39.0>}
View registered nodes
([email protected])2> redgrid:nodes().
[{'[email protected]',[<<"ip">>, <<"localhost">>]},
{'[email protected]',[{<<"ip">>, <<"localhost">>}]}]
([email protected])3> [node()|nodes()].
['[email protected]', '[email protected]']
Update meta data for bar node
([email protected])4> redgrid:update_meta([{weight, 50}]).
ok
View registered nodes (including updated meta data for bar)
([email protected])2> redgrid:nodes().
[{'[email protected]',[<<"ip">>, <<"localhost">>]},
{'[email protected]',[{<<"ip">>,<<"localhost">>},
{<<"weight">>, <<"50">>}]}]
This diagram demonstrates what's happening underneath the covers when the foo node joins a cluster comprised of a single node (bar).
LOCAL_IP: The IP written to Redis to which other nodes will attempt to connect
DOMAIN: Used to build Redis key and channel names
VERSION: Used to build Redis key and channel names