Documentation ¶
Overview ¶
Package consistenthash provides a flexible hash ring. 支持自定义虚拟节点副本数,支持自定义哈希函数,支持添加删除节点的一致性hash库。
Index ¶
- Variables
- type Hash32
- type HashRing
- func (m *HashRing) Add(nodes ...string) error
- func (m *HashRing) Get(key string) (string, error)
- func (m *HashRing) IsEmpty() bool
- func (m *HashRing) Remove(nodes ...string)
- func (m *HashRing) Reset(nodes ...string) error
- func (m *HashRing) ResetAll(replicas uint16, hash Hash32, nodes ...string) error
- func (m *HashRing) RingInfo() string
- type U32Slice
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrRingEmpty "ring empty" ErrRingEmpty = errors.New("ring empty") // ErrRingFull "ring full" ErrRingFull = errors.New("ring full") )
Functions ¶
This section is empty.
Types ¶
type HashRing ¶
type HashRing struct { HashFunc Hash32 // hash func for key and for node sync.RWMutex // contains filtered or unexported fields }
HashRing core struct for hashring 一致性hash环的结构体
func New ¶
New creates a new hash ring. With default hash function crc32. 创建hash环,默认hash函数为crc32.ChecksumIEEE
func (*HashRing) Add ¶
Add adds some nodes to the hashring. If return error,MUST ResetAll hashring, typically by adjusting the replicas! 返回错误,必须接收和处理
func (*HashRing) Reset ¶
Reset reset nodes If return error,MUST ResetAll hashring, typically by adjusting the replicas! 返回错误,必须接收和处理
Click to show internal directories.
Click to hide internal directories.