Skip to content

yguilai/go-consistenthash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-consistenthash

a consistent hash implementation that inspired by go-zero

this library is without third dependency, the go sdk should be since 1.18, because of this library use generic feature

Usage

go get github.com/yguilai/go-consistenthash

Simple Use Case

package main

import (
	"fmt"
	consistenthash "github.com/yguilai/go-consistenthash"
)

type StringNode string

// implement consistenthash.Node interface
func (s StringNode) String() string {
	return string(s)
}

func main() {
	// use default options
	ch := consistenthash.New[StringNode]()
	nodes := []StringNode{"localhost:1", "localhost:2", "localhost:3"}
	ch.Add(nodes...)

	node, ok := ch.Get("key1")
	fmt.Printf("node: %v, ok: %v", node, ok)
}

About

a consistent hash implementation in go

Topics

Resources

License

Stars

Watchers

Forks

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy