一个实现一致哈希和带有限负载的一致哈希的 Go 库。
A Golang implementation of Consistent Hashing and Consistent Hashing With Bounded Loads.
https://en.wikipedia.org/wiki/Consistent_hashing
https://research.googleblog.com/2017/04/consistent-hashing-with-bounded-loads.html
package main
import (
"log"
"github.com/lafikl/consistent"
)
func main() {
c := consistent.New()
// adds the hosts to the ring
c.Add("127.0.0.1:8000")
c.Add("92.0.0.1:8000")
// Returns the host that owns `key`.
//
// As described in https://en.wikipedia.org/wiki/Consistent_hashing
//
// It returns ErrNoHosts if the ring has no hosts in it.
host, err := c.Get("/app.html")
if err != nil {
log.Fatal(err)
}
log.Println(host)
}
…https://godoc.org/github.com/lafikl/consistent
…暂无开放 Issues,或尚未同步最近议题。