一致性哈希库
Go to file
2020-08-03 06:41:40 +00:00
hashring_test.go add pkg 2016-08-15 22:52:09 +08:00
hashring.go remove RWMutex init 2018-04-26 15:31:19 +08:00
README.md 更新 'README.md' 2020-08-03 06:41:40 +00:00

hashring

A golang consistent hashring

Install

go get golib.gaore.com/GaoreGo/hashring

Usage

// 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")