您最多能選擇 25 個主題
主題必須以字母或數字為開頭,可包含連接號「-」且最長為 35 個字元。
|
4 年前 | |
---|---|---|
README.md | 4 年前 | |
hashring.go | 6 年前 | |
hashring_test.go | 8 年前 |
README.md
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")