Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/reset/hash-ring-ex
A consistent hash ring implemention for Elixir
https://github.com/reset/hash-ring-ex
Last synced: 25 days ago
JSON representation
A consistent hash ring implemention for Elixir
- Host: GitHub
- URL: https://github.com/reset/hash-ring-ex
- Owner: reset
- License: apache-2.0
- Created: 2014-06-30T02:46:20.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-02-24T09:59:31.000Z (over 7 years ago)
- Last Synced: 2024-09-14T10:40:30.210Z (about 2 months ago)
- Language: Elixir
- Homepage:
- Size: 167 KB
- Stars: 24
- Watchers: 2
- Forks: 18
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - A consistent hash-ring implementation for Elixir. (Algorithms and Data structures)
- fucking-awesome-elixir - hash_ring_ex - A consistent hash-ring implementation for Elixir. (Algorithms and Data structures)
- awesome-elixir - hash_ring_ex - A consistent hash-ring implementation for Elixir. (Algorithms and Data structures)
README
# HashRing
[![Build Status](https://travis-ci.org/reset/hash-ring-ex.png?branch=master)](https://travis-ci.org/reset/hash-ring-ex)
A consistent hash-ring implemention leveraging the excellent [C hash-ring lib](https://github.com/chrismoos/hash-ring) by [Chris Moos](https://github.com/chrismoos) for Elixir.
## Requirements
* Elixir 0.15.1 or newer
## Installation
Add HashRing as a dependency in your `mix.exs` file
```elixir
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
```elixir
{: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
```elixir
{:ok, "first_node"} = HashRing.find(pid, "my_key")
```Nodes can also be easily dropped
```elixir
: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 or `start/1`
```elixir
{: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)
```elixir
{:ok, pid} = HashRing.start_link(replicas: 5)
```And the standard GenServer options can be passed in, too
```elixir
{:ok, pid} = HashRing.start_link(name: :my_hash_ring)
```## Authors
Jamie Winsor ()