一致性哈希库
Go to file
2019-12-21 21:32:02 +08:00
.gitignore fast init 2019-12-21 21:32:02 +08:00
go.mod fast init 2019-12-21 21:32:02 +08:00
go.sum fast init 2019-12-21 21:32:02 +08:00
hashring_test.go fast init 2019-12-21 21:32:02 +08:00
hashring.go fast init 2019-12-21 21:32:02 +08:00
README.md edit README.md 2018-04-09 11:34:07 +08:00

hashring

A golang consistent hashring

Install

go get github.com/g4zhuj/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")