朱江 b84728bd22 | 7年前 | |
---|---|---|
README.md | 7年前 | |
hashring.go | 7年前 | |
hashring_test.go | 7年前 |
A golang consistent hashring
go get github.com/g4zhuj/hashring
// virtualSpots means virtual spots created by each node
nodeWeight := make(map[string]int)
nodeWeight["node1"] = 1
nodeWeight["node2"] = 1
nodeWeight["node3"] = 2
vitualSpots := 100
hash := NewHashRing(virtualSpots)
//add nodes
hash.AddNodes(nodeWeight)
//remove node
hash.RemoveNode("node3")
//add node
hash.AddNode("node3", 3)
//get key's node
node := hash.GetNode("key")