consistenthash

package
v0.0.0-...-4b0e997 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package consistenthash provides a ring hash implementation.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoNodes is returned when a hash is requested containing no nodes.
	ErrNoNodes = errors.New(
		"there must be at least one node, otherwise keys cannot be mapped")
)

Functions

This section is empty.

Types

type Ring

type Ring struct {
	// contains filtered or unexported fields
}

Ring is an immutable ring hash.

func NewRing

func NewRing(replicas int, nodes ...string) (*Ring, error)

NewRing creates a new consistent hash ring, initialised with the provided nodes (order does not matter). When the node list changes, a new hash should be created; updating a hash in place is not supported, as it would drastically increase the time complexity of lookups, which are expected to be the vastly more common operation. Replicas must be at least one, and should be greater when there are few nodes in order to reduce the variance in load amongst them. 50 is usually a reasonable choice.

func (*Ring) Get

func (m *Ring) Get(key string) string

Get returns the node in the hash that owns the provided key.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL