一致性散列库:
go get stathat.com/c/consistent
创建:
cons := consistent.New()
cons.Add("CacheA")
cons.Add("CacheB")
cons.Add("CacheC")
cons.Add("cacheX")
测试1:
server, err := cons.Get("user_89138238")
if err != nil {
fmt.Println(err)
}
fmt.Println("server:", server)
output: CacheA
继续测试2:
cons.Remove("CacheA")
server, err = cons.Get("user_89138238")
if err != nil {
fmt.Println(err)
}
fmt.Println("server:", server)
output: CacheX
继续测试3:
cons.Add("CacheA")
server, err = cons.Get("user_89138238")
if err != nil {
fmt.Println(err)
}
fmt.Println(server)
output: CacheA