ketama

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultReplicas 默认的虚拟节点数
	DefaultReplicas = 100
	// MaxWeight 最大节点权重
	MaxWeight = DefaultReplicas
)

Variables

This section is empty.

Functions

func DefaultHash

func DefaultHash(data []byte) uint64

DefaultHash 默认 hash 生成函数

Types

type HashFunc

type HashFunc func(data []byte) uint64

HashFunc hash 生成函数

type Ketama

type Ketama struct {
	// contains filtered or unexported fields
}

Ketama 基于 Ketama 算法的一致性 hash 负载均衡器

func New

func New() *Ketama

New 新建一个 Ketama 对象

func NewCustom

func NewCustom(replicas int, hashFunc HashFunc) *Ketama

NewCustom 新建一个自定义 Ketama 对象

func (*Ketama) Add

func (k *Ketama) Add(node string)

Add 添加节点

func (*Ketama) AddWithReplicas

func (k *Ketama) AddWithReplicas(node string, replicas int)

AddWithReplicas 添加带虚拟节点的节点

func (*Ketama) AddWithWeight

func (k *Ketama) AddWithWeight(node string, weight int)

AddWithWeight 添加带权重的节点,权重值范围在 [1-100] 中

func (*Ketama) Get

func (k *Ketama) Get(key string) (string, bool)

Get 获取节点

func (*Ketama) Remove

func (k *Ketama) Remove(nodes ...string)

Remove 移除节点

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL