riak / doc / basic-client.txt

Diff from to

doc/basic-client.txt

 Each bit of data in Riak is stored in a "bucket" at a "key" that is
 unique to that bucket.  The bucket is intended as an organizational
 aid, for example to help segregate data by type, but Riak doesn't care
-what values it stores, so choose whatever scheme suits you.  Bucket
-must be an atom, and key must be a list.
+what values it stores, so choose whatever scheme suits you.  Buckets
+and keys must both be binaries.
 
 Before storing your data, you must wrap it in a riak_object:
 
-4> Object = riak_object:new(groceries, "mine", ["eggs", "bacon"]).
-{r_object,groceries,"mine",
+4> Object = riak_object:new(<<"groceries">>, <<"mine">>, ["eggs", "bacon"]).
+{r_object,<<"groceries">>,<<"mine">>,
           [{r_content,{dict,0,16,16,8,80,48,
                             {[],[],[],[],[],[],[],[],[],[],[],[],[],[],...},
                             {{[],[],[],[],[],[],[],[],[],[],[],[],...}}},
 At some point you'll want that data back.  Using the same bucket and
 key you used before:
 
-6> {ok, O} = Client:get(groceries, "mine", 1).
-{ok,{r_object,groceries,"mine",
+6> {ok, O} = Client:get(<<"groceries">>, <<"mine">>, 1).
+{ok,{r_object,<<"groceries">>,<<"mine">>,
               [{r_content,{dict,2,16,16,8,80,48,
                                 {[],[],[],[],[],[],[],[],[],[],[],[],...},
                                 {{[],[],[],[],[],[],
 to get ["eggs","bacon"], and you want to add "milk" to it.  The
 easiest way is:
 
-8> {ok, Oa} = Client:get(groceries, "mine", 1).
+8> {ok, Oa} = Client:get(<<"groceries">>, <<"mine">>, 1).
 ...
 9> Ob = riak_object:update_value(Oa, ["milk"|riak_object:get_value(Oa)]).
 ...
 Riak.  You can get your updated object to convince yourself that your
 list is updated:
 
-11> {ok, Oc} = Client:get(groceries, "mine", 1).
+11> {ok, Oc} = Client:get(<<"groceries">>, <<"mine">>, 1).
 ...
 12> riak_object:get_value(Oc).
 ["milk","eggs","bacon"].
 
 1> {ok, C} = riak:client_connect("127.0.0.1", 9000, mycookie).
 ...
-2> ok = C:put(riak_object:new(groceries, "mine", ["bread","cheese"]), 1).
+2> ok = C:put(riak_object:new(<<"groceries">>, <<"mine">>, ["bread","cheese"]), 1).
 ...
-3> {ok, O} = C:get(groceries, "mine", 1).
+3> {ok, O} = C:get(<<"groceries">>, <<"mine">>, 1).
 ...
 4> riak_object:get_value(O).
 ** exception error: no match of right hand side value 
 it's necessary to find out what keys are available (when debugging,
 for example).  For that, there is list_keys:
 
-1> Client:list_keys(groceries).
+1> Client:list_keys(<<"groceries">>).
 {ok, ["mine"]}.
 
 Note that keylist updates are asynchronous to the object storage
 Throwing away data is quick and simple: just use the delete function
 in the riak_client module:
 
-1> Client:delete(groceries, "mine", 1).
+1> Client:delete(<<"groceries">>, <<"mine">>, 1).
 ok
 
 As with get and put, delete has an arity-3 function and an arity-4
 Issuing a delete for an object that does not exist returns an error
 tuple.  For example, calling the same delete as above a second time:
 
-2> Client:delete(groceries, "mine", 1).
+2> Client:delete(<<"groceries">>, <<"mine">>, 1).
 {error,notfound}
 
 
 To view the settings for a bucket, use the get_bucket function in the
 riak_client module:
 
-1> Client:get_bucket(groceries).
-[{name,groceries},
+1> Client:get_bucket(<<"groceries">>).
+[{name,<<"groceries">>},
  {n_val,3},
  {allow_mult,true},
  {linkfun,{no_mod,no_fun}},
 this document.  There, we altered the allow_mult setting for the
 groceries bucket:
 
-8> C:set_bucket(groceries, [{allow_mult, false}]).
+8> C:set_bucket(<<"groceries">>, [{allow_mult, false}]).
 ok
 
 The allow_mult setting is one that will "just work", in that if any
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.