読者です 読者をやめる 読者になる 読者になる

riak-erlang-client を触ってみた

https://github.com/basho/riak-erlang-client

git clone して make すれば動きます。

通信はPB です。ただ中身で使うデータは Erlang の binary です。
term_to_binary -> binary_to_term という方法が使えます。

サンプルそのままですが ... riak は 1 ノードでデフォルトのまま動かしてます。

% erl -pa ebin deps/*/ebin
Erlang R14B03 (erts-5.8.4) [source] [64-bit] [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.8.4  (abort with ^G)
1> {ok, Pid} = riakc_pb_socket:start_link("127.0.0.1", 8087).
{ok,<0.33.0>}
2> riakc_pb_socket:ping(Pid).
pong
3> Object = riakc_obj:new(<<"groceries">>, <<"mine">>, <<"eggs & bacon">>).
{riakc_obj,<<"groceries">>,<<"mine">>,undefined,[],
           undefined,<<"eggs & bacon">>}
4> riakc_pb_socket:put(Pid, Object).
ok
5> {ok, O} = riakc_pb_socket:get(Pid, <<"groceries">>, <<"mine">>).
{ok,{riakc_obj,<<"groceries">>,<<"mine">>,
               <<107,206,97,96,96,96,204,96,202,5,82,44,140,91,100,158,
                 101,48,37,50,230,177,50,...>>,
               [{{dict,2,16,16,8,80,48,
                       {[],[],[],[],[],[],[],[],[],[],[],[],...},
                       {{[],[],[],[],[],[],[],[],[],[],...}}},
                 <<"eggs & bacon">>}],
               undefined,undefined}}
9> {ok, Oa} = riakc_pb_socket:get(Pid, <<"groceries">>, <<"mine">>).
{ok,{riakc_obj,<<"groceries">>,<<"mine">>,
               <<107,206,97,96,96,96,202,96,202,5,82,44,140,91,100,158,
                 101,48,37,50,230,177,50,...>>,
               [{{dict,2,16,16,8,80,48,
                       {[],[],[],[],[],[],[],[],[],[],[],[],...},
                       {{[],[],[],[],[],[],[],[],[],[],...}}},
                 <<"eggs & bacon">>}],
               undefined,undefined}}
10> Ob = riakc_obj:update_value(Oa, <<"milk, ", (riakc_obj:get_value(Oa))/binary>>).
{riakc_obj,<<"groceries">>,<<"mine">>,
           <<107,206,97,96,96,96,202,96,202,5,82,44,140,91,100,158,
             101,48,37,50,230,177,50,36,240,...>>,
           [{{dict,2,16,16,8,80,48,
                   {[],[],[],[],[],[],[],[],[],[],[],[],[],[],...},
                   {{[],[],[],[],[],[],[],[],[],[],[[...]],[],...}}},
             <<"eggs & bacon">>}],
           undefined,<<"milk, eggs & bacon">>}
11> {ok, Oc} = riakc_pb_socket:put(Pid, Ob, [return_body]).
{ok,{riakc_obj,<<"groceries">>,<<"mine">>,
               <<107,206,97,96,96,96,202,96,202,5,82,108,205,73,12,166,
                 247,52,50,152,18,25,243,...>>,
               [{{dict,2,16,16,8,80,48,
                       {[],[],[],[],[],[],[],[],[],[],[],[],...},
                       {{[],[],[],[],[],[],[],[],[],[],...}}},
                 <<"milk, eggs & bacon">>}],
               undefined,undefined}}