I am wanting to implement a postcommit hook for riak that decrements a counter in a map in another bucket. However I am having a bit of trouble dealing with the riak datatypes.
Here is me attempting from riak console
:
(riak@127.0.0.1)9>{ok, C} = riak:local_client().
{ok,{riak_client,['riak@127.0.0.1',undefined]}}
(riak@127.0.0.1)10>{ok, Obj} = C:get({<<"product">>, <<"default">>}, <<"1">>).
{ok,{r_object,{<<"product">>,<<"default">>},
<<"1">>,
[{r_content,{dict,5,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],...},
{{[],[],[],[],
[[<<"dot">>|{<<"#\tþù"...>>,{...}}]],
[],[],[],[],[],...}}},
<<69,2,0,0,0,11,114,105,97,107,95,100,116,95,109,97,112,
77,1,...>>}],
[{<<35,9,254,249,108,41,151,242>>,{1,63593788980}}],
{dict,1,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],...},
{{[],[],[],[],[],[],[],[],[],[],[],...}}},
undefined}}
(riak@127.0.0.1)11> Mp = riak_object:get_value(O3).
<<69,2,0,0,0,11,114,105,97,107,95,100,116,95,109,97,112,
77,1,131,80,0,0,0,206,120,1,203,96,...>>
(riak@127.0.0.1)12> MpP = riak_dt_map:from_binary(Mp).
{error,invalid_binary}
product
bucket datatype is set to map
. Each object stored should have a counter called quantity
which I'd like to decrement.
However I cannot find any documentation or sample code dealing with datatypes in a pre or post commit context. (actually examples of any kind are few). I've been reading the source of riak_client and riak_dt_map but I am new to erlang so I'm making slow progress and would appreciate some help.