consistenthash

package
v0.0.0-...-a0a356d Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = &Config{
	DefaultReplicas:      50,
	MinReplicas:          10,
	MaxReplicas:          200,
	HashFunc:             crc32.ChecksumIEEE,
	LoadBalanceThreshold: 0.25,
}

DefaultConfig 默认配置

Functions

This section is empty.

Types

type Config

type Config struct {
	// 每个真实节点对应的虚拟节点数
	DefaultReplicas int
	// 最小虚拟节点数
	MinReplicas int
	// 最大虚拟节点数
	MaxReplicas int
	// 哈希函数
	HashFunc func(data []byte) uint32
	// 负载均衡阈值,超过此值触发虚拟节点调整
	LoadBalanceThreshold float64
}

Config 一致性哈希配置

type Map

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

Map 一致性哈希实现

func New

func New(opts ...Option) *Map

New 创建一致性哈希实例

func (*Map) Add

func (m *Map) Add(nodes ...string) error

Add 添加节点

func (*Map) Get

func (m *Map) Get(key string) string

Get 获取节点

func (*Map) GetStats

func (m *Map) GetStats() map[string]float64

GetStats 获取负载统计信息

func (*Map) Remove

func (m *Map) Remove(node string) error

Remove 移除节点

type Option

type Option func(*Map)

Option 配置选项

func WithConfig

func WithConfig(config *Config) Option

WithConfig 设置配置

Jump to

Keyboard shortcuts

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