Riak Core Demo (KV store)
This is a riak demo application following the elixir tutorials by
Gpad and adapting them to erlang
(@GPad/create-a-riak-core-application-in-elixir-part-1-41354c1f26c3">Part 1,
@GPad/create-a-riak-core-application-in-elixir-part-2-88bdec73f368">Part 2,
@GPad/create-a-riak-core-application-in-elixir-part-3-8bac36632be0">Part 3,
@GPad/create-a-riak-core-application-in-elixir-part-4-728512ece224">Part 4)
$ rebar3 compile
Start the first node:
rebar3 shell --name test1@127.0.0.1 --config config/vars_dev1.config
1> application:ensure_all_started(riak_core_demo).
Start the second node:
rebar3 shell --name test2@127.0.0.1 --config config/vars_dev2.config
1> application:ensure_all_started(riak_core_demo).
Join the two nodes together (run from the first node):
2> riak_core:join('test2@127.0.0.1').
Test the ping (you can run from both nodes):
3> riak_core_demo:ping().
You should see messages from console like:
{pong, ....}
and in one of the two nodes (it’s pseudo random) a message like:
[ping received] from ...
riak_core_demo:put(a, 1).
riak_core_demo:put(b, 2).
...
riak_core_demo:get(a).
riak_core_demo:get(b).
After you insert many data in the store, just try to disconnect
the second node from the cluster:
riak_core:leave().
In the console you should be able to see the different messages.
Automatically, all information stored in the second node will be transfered
to the first node.
To reconnect again the second node, simply:
application:ensure_all_started(riak_core_demo).
riak_core:join('test1@127.0.0.1').
Again, you will see the handoff of some process from the first node and
part of the data will be transfered to the second node.
After you insert many data in the store, try to get the list of keys stored in
all nodes or list of values:
riak_core_demo:keys().
riak_core_demo:values().
Show cluster status:
riak_core_demo:status().