ketama

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2023 License: BSD-3-Clause Imports: 3 Imported by: 0

README

Ketama

Package ketama implements a consistent hashing ring (on md5).

https://godoc.org/github.com/hit9/ketama

Example

package main

import (
	"fmt"
	"github.com/hit9/ketama"
)

func main() {
	ring := ketama.NewRing([]*ketama.Node{
		ketama.NewNode("127.0.0.1:8000", "binding data0", 1),
		ketama.NewNode("127.0.0.1:8001", "binding data1", 1),
		ketama.NewNode("127.0.0.1:8002", "binding data2", 1),
		ketama.NewNode("127.0.0.1:8003", "binding data3", 1),
		ketama.NewNode("127.0.0.1:8004", "binding data3", 1),
	})
	fmt.Printf("%v\n", ring.Get("key1"))
}

Please checkout ketama_example.go for more .

License

BSD.

Documentation

Overview

Package ketama implements a consistent hashing ring (on md5).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByHash

type ByHash []*Node

ByHash implements sort.Interface.

func (ByHash) Len

func (s ByHash) Len() int

func (ByHash) Less

func (s ByHash) Less(i, j int) bool

func (ByHash) Swap

func (s ByHash) Swap(i, j int)

type Node

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

Node is the hashing ring node.

func NewNode

func NewNode(key string, data interface{}, weight uint) *Node

NewNode creates a new Node.

func (*Node) Data

func (n *Node) Data() interface{}

Data returns the Node data.

func (*Node) Key

func (n *Node) Key() string

Key returns the Node key.

func (*Node) Weight

func (n *Node) Weight() uint

Weight returns the Node weight.

type Ring

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

Ring is the ketama hashing ring.

func NewRing

func NewRing(nodes []*Node) *Ring

NewRing creates a new Ring.

func (*Ring) Get

func (r *Ring) Get(key string) *Node

Get node by key from ring. Returns nil if the ring is empty.

Jump to

Keyboard shortcuts

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