cd ~/riak
erl -name zed@127.0.0.1 -setcookie riak -pa apps/riak/ebin
In the shell:
> {ok, Client} = riak:client_connect('riak@127.0.0.1').
{ok,{riak_client,'riak@127.0.0.1',<<6,201,208,64>>}}
> Client:put(riak_object:new(<<"groceries">>, <<"mine">>, ["eggs", "bacons"]), 1).
ok
> Client:put(riak_object:new(<<"groceries">>, <<"yours">>, ["eggs", "sausages"]), 1).
ok
> Count = fun(G, 'undefined', 'none') ->
[dict:from_list([{I, 1} || I <- riak_object:get_value(G)])]
end.
> Merge = fun(Gcounts, 'none') ->
[lists:foldl(fun(G, Acc) ->
dict:merge(fun(_, X, Y) -> X+Y end, G, Acc)
end, dict:new(), Gcounts)]
end.
> {ok, [R]} = Client:mapred([{<<"groceries">>, <<"mine">>},
{<<"groceries">>, <<"yours">>}],
[{'map', {'qfun', Count}, 'none', false},
{'reduce', {'qfun', Merge}, 'none', true}]).
{ok,[{dict,...
> dict:to_list(R).
[{"eggs",2},{"susages",1},{"bacons",1}]
For the server, I used an absolutely standard configuration:
$ hg clone http://hg.basho.com/riak/
$ cd riak
$ ./rebar compile generate
$ cd rel
$ ./riak/bin/riak start