What is the syntax for setting lwwreg
register values in CRDT Map
on server side in Riak? I tried a code like below which doesn't seem to be valid:
%% Obj is a map object to which we want to add/set a register "uname" with value
%% "ahmed"
riak_kv_crdt:update(Obj,<<"testing">>,{crdt_op,riak_dt_map,
{update,[{assign,<<"uname">>,<<"ahmed">>}]},undefined})
I get an error about the operation being invalid - I looked around in source code for riak_dt_map.erl
but still can't figure out correct syntax:
> riak_kv_crdt:update(Obj,<<"testing">>,{crdt_op,riak_dt_map,{update,
[{assign,<<"uname">>,<<"ahmed">>}]},undefined}).
** exception error: no function clause matching
riak_dt_map:apply_ops([{assign,<<"uname">>,<<"ahmed">>}],
{<<"testing">>,1},
{[{<<"testing">>,1}],
.....
Will appreciate pointers on correct syntax.
Figured it out. The correct syntax is below - the key must be accompanied by the type of the field which is riak_dt_lwwreg
in this case, and assign
operation must be specified for register value - so, the syntax becomes:
riak_kv_crdt:update(Obj,<<"testing">>,{crdt_op,riak_dt_map,{update,
[{update,{<<"uname">>,riak_dt_lwwreg},{assign,<<"ahmed">>}}]},undefined})