Popularity
4.9
Growing
Activity
0.0
Stable
22
1
19

Monthly Downloads: 11
Programming language: Elixir
License: Apache License 2.0
Latest version: v1.1.2

hash_ring_ex alternatives and similar packages

Based on the "Algorithms and Data structures" category.
Alternatively, view hash_ring_ex alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of hash_ring_ex or a related project?

Add another 'Algorithms and Data structures' Package

README

HashRing

Build Status

A consistent hash-ring implemention leveraging the excellent C hash-ring lib by Chris Moos for Elixir.

Requirements

  • Elixir 0.15.1 or newer

Installation

Add HashRing as a dependency in your mix.exs file

defp deps do
  [
    {hash_ring_ex: "~> 1.0"}
  ]
end

Then run mix deps.get in your shell to fetch the dependencies.

Usage

Start or supervise a new HashRing with HashRing.start_link/1 or HashRing.start/1 and add some nodes

{:ok, pid} = HashRing.start_link
:ok = HashRing.add(pid, "first_node")
:ok = HashRing.add(pid, "second_node")

Then find the appropriate node for your key

{:ok, "first_node"} = HashRing.find(pid, "my_key")

Nodes can also be easily dropped

:ok = HashRing.drop(pid, "first_node")
{:ok, "second_node"} = HashRing.find(pid, "my_key")

Configuring

Started rings will use an MD5 hash function by default. In tests MD5 is on average about 25% faster than sha1. The hashing function to use can be specified as an option sent to start_link/1 orstart/1`

{:ok, md5}  = HashRing.start_link(hash_func: :md5)
{:ok, sha1} = HashRing.start_link(hash_func: :sha1)

The number of replicas can be configured, too (default: 128)

{:ok, pid} = HashRing.start_link(replicas: 5)

And the standard GenServer options can be passed in, too

{:ok, pid} = HashRing.start_link(name: :my_hash_ring)

Authors

Jamie Winsor ([email protected])