1. Justin Sheehy
  2. riak


riak / doc / basic-client.txt

Diff from to

File doc/basic-client.txt

  • Ignore whitespace
 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"]).
+4> Object = riak_object:new(<<"groceries">>, <<"mine">>, ["eggs", "bacon"]).
 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).
+6> {ok, O} = Client:get(<<"groceries">>, <<"mine">>, 1).
 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).
 1> {ok, C} = riak:client_connect("", 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).
 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).
 To view the settings for a bucket, use the get_bucket function in the
 riak_client module:
-1> Client:get_bucket(groceries).
+1> Client:get_bucket(<<"groceries">>).
 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}]).
 The allow_mult setting is one that will "just work", in that if any