Provides pooled Riak connections for Elixir apps. Re-connects automatically upon disconnection.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Provides pooled Riak connections for Elixir. Re-connects automatically upon disconnection.

Can also be used in Erlang. Based on Basho's Riak erlang client


  • To use this in your Elixir project, add it to your dependency list in mix.exs

    defp deps do
        {:riak_pool, github: "HashNuke/riak_pool"}
  • Run mix deps.get

Starting RiakPool

There are two ways to start RiakPool


  • RiakPool.start_link(address, port)

    RiakPool.start_link '', 8087
  • RiakPool.start_link(address, port, options)

    RiakPool.start_link('', 8087, [
        pool_options: [size: 6, max_overflow: 12]

Valid options are

  • pool_options - options for the pool. Default value for size is 5 and max_overflow is 10.
  • connection_options - options for the Riak connection
  • retry_interval - incase of disconnection from Riak, this is the number of seconds (interval), at which a re-connection will be tried for. By default the value is 60 (seconds).

Add it to your supervision tree

Here's an example. Notice the init function.

defmodule YourApp.Supervisor do
  use Supervisor.Behaviour

  def start_link do
    :supervisor.start_link(__MODULE__, [])

  def init([]) do
    children = [
      # We are connecting to localhost, on port 8087.
      # You can also pass a third argument for size options
      worker(RiakPool, ['', 8087])
    supervise children, strategy: :one_for_one


The library provides the following functions.

Testing Riak connection

Used to test if connection to your database is fine. Should return :pong.


Put objects


Used to create or update values in the database. Accepts a riak object, created with the :riakc_obj module as the argument. Refer to this blog post on how to use the :riakc_obj module to encapsulate your data.

Get objects

RiakPool.get(bucket, key)

Used to get the value stored for a key from in a bucket. It accepts a bucket name and the key.


RiakPool.delete(bucket, key)

Used to delete a key/value from a bucket in the database. It accepts a bucket name and the key to delete.

Running your own stuff

Pass a function that accepts a worker pid as the argument. It'll run the function for you.

Use this function, to perform other tasks, that this library doesn't provide helper functions for. You can then use the worker pid with the :riakc_pb_socket module to connect to Riak and do something on your own.

Here's an example that lists keys in the "students" bucket: fn(worker)->
  :riakc_pb_socket.list_keys worker, "students"


Akash Manohar wrote this.

RiakPool is available in the public domain. Or optionally under the MIT License.

If you use it somewhere, send me an email to tell me about it - that'll make me extremely happy.