ExRiak
ExRiak is simple wrapper around riak-erlang-client, designed to let you follow Elixir coding conventions, while providing the flexibility drop down to the underlying erlang client when needed. Here's an example:
# Can use the :riakc_pb_socket directly from erlang
{:ok, conn} = :riakc_pb_socket.start_link("127.0.0.1", 8087)
with {:ok, obj} <- ExRiak.PBSocket.get(conn, "tv_show_ratings", "simpsons"),
# Can drop down to erlang if nessecary
obj <- :riakc_obj.update_value(obj, 10) do
# Save to riak. Will raise a ExRiak.SiblingsError if there are unresolved
# siblings instead of throwing :siblings. Can also use ExRiak.PBSocket.put/2
# to pattern match the result.
ExRiak.PBSocket.put!(conn, obj)
endSee the online documentation for more information.
Usage
Add ExRiak to your list of dependencies in mix.exs:
def deps do
[{:ex_riak, "~> 0.4.1"}]
end
Then run mix deps.get in your shell to fetch the dependencies.
Interop with riak-erlang-client
This library closely mirrors the riak-erlang-client's API. Below are the
mappings between ExRiak modules and the riak-erlang-client modules.
| Elixir | Erlang |
|---|---|
ExRiak.PBSocket | :riakc_pb_socket |
ExRiak.Object | :riakc_obj |
More information on these modules is available in the online documentation.
Development
Running tests
Before running tests, you need will need to update your riak setup:
Update your
riak.confto set up the appropriate backend. (If riak was installed with homebrew, the riak config file will be at/usr/local/Cellar/riak/2.2.3/libexec/etc/riak.conf.) Replace the line containingstorage_backendwith the following:storage_backend = multi multi_backend.ex_riak_leveldb.storage_backend = leveldb multi_backend.ex_riak_leveldb.leveldb.data_root = $(platform_data_dir)/ex_riak_leveldbRun
riak start.Run the following commands to create the ExRiak bucket types.
riak-admin bucket-type create ex_riak riak-admin bucket-type create ex_riak_maps '{"props":{"datatype":"map"}}' riak-admin bucket-type create ex_riak_leveldb '{"props":{"backend":"ex_riak_leveldb"}}' riak-admin bucket-type activate ex_riak riak-admin bucket-type activate ex_riak_maps riak-admin bucket-type activate ex_riak_leveldb
After that, make sure you've got Elixir 1.5+ installed and then:
$ mix deps.get
$ mix test