Taste of Riak

Reading Objects From Riak

Now that we have a few objects stored, let’s retrieve them and make sure they contain the values we expect. The following will return a Riak object data structure:

> (set `#(ok ,result) (lric:get pid my-bucket key-1))
#(ok
  #(riakc_obj
    #B(116 101 115 116)
    #B(107 101 121)
    #B(107 206 97 96 96 96 204 96 ...)
    (#(#(dict
         2
         16
         16
         8
         80
         48
         #(() () () () () () () () () () () () ...)
         #(#(() () () () () () () () () () ...)))
       #B(97 32 118 97 108 117 101)))
    undefined
    undefined))

To get the value from that data structure:

> (binary_to_list (lrico:get-value result))
"a value"

We can, of course, do it all in one shot:

> (binary_to_term
    (lrico:get-value
      (element 2 (lric:get pid my-bucket key-2))))
2