First, let’s create a few Riak objects. For these examples we'll be using the bucket test
.
> (set my-bucket (binary "test"))
#B(116 101 115 116)
> (set key-1 (binary "key 1"))
#B(107 101 121 32 49)
> (set value-1 (binary "a value for key 1"))
#B(97 32 118 97 108 117 101 32 102 ...)
With these in place, we can create an object:
> (set obj-1 (lrico:new my-bucket key-1 value-1))
#(riakc_obj
#B(116 101 115 116)
#B(107 101 121 32 49)
undefined
()
undefined
#B(97 32 118 97 108 117 101 32 102 ...))
and then store it in Riak:
> (lric:put pid obj-1)
ok
If we're not storing string values, we can skip the (binary ...)
call:
> (set key-2 (binary "key 2"))
#B(107 101 121 32 50)
> (set value-2 2)
2
> (set obj-2 (lrico:new my-bucket key-2 value-2))
#(riakc_obj ...)
> (lric:put pid obj-2)
ok
We can also store more complicated data structures:
> (set key-3 (binary "key 3"))
#B(107 101 121 32 50)
> (set value-3 `#(value ,(binary "7 times 6")))
#(value #B(55 32 116 105 109 101 115 32 54))
> (set obj-3 (lrico:new my-bucket key-3 value-3))
#(riakc_obj ...)
> (lric:put pid obj-3)
ok