Documentation
¶
Index ¶
- Constants
- Variables
- func New(buckets []storage.Bucket, opts ...Option) (storage.Selector, error)
- type Balancer
- type Consistent
- func (c *Consistent) Add(cache Node, weigth int)
- func (c *Consistent) Get(name string) (Node, error)
- func (c *Consistent) GetN(name string, n int) ([]Node, error)
- func (c *Consistent) Members() []string
- func (c *Consistent) Remove(cache Node, weigth int)
- func (c *Consistent) Set(caches []Node)
- func (c *Consistent) SetNumberOfReplicas(num int)
- type Node
- type Option
Constants ¶
const ( Name = "hashring" DefaultReplicas = 20 )
Variables ¶
var ErrEmptyCircle = errors.New("empty circle")
ErrEmptyCircle is the error returned when trying to get an element when nothing has been added to hash.
Functions ¶
Types ¶
type Balancer ¶
type Balancer struct {
// contains filtered or unexported fields
}
type Consistent ¶
type Consistent struct {
sync.RWMutex // tavern 只有初始化时才写,其他都是读,故不需要用锁
NumberOfReplicas int
UseFnv bool
// contains filtered or unexported fields
}
Consistent holds the information about the members of the consistent hash circle.
func NewConsistent ¶
func NewConsistent(caches []Node, replicas int) *Consistent
NewConsistent creates a new Consistent object with a default setting of 20 replicas for each entry. To change the number of replicas, set NumberOfReplicas before adding entries.
func (*Consistent) Add ¶
func (c *Consistent) Add(cache Node, weigth int)
Add inserts a string element in the consistent hash.
func (*Consistent) Get ¶
func (c *Consistent) Get(name string) (Node, error)
Get returns an element close to where name hashes to in the circle.
func (*Consistent) GetN ¶
func (c *Consistent) GetN(name string, n int) ([]Node, error)
GetN returns the N closest distinct elements to the name input in the circle.
func (*Consistent) Members ¶
func (c *Consistent) Members() []string
func (*Consistent) Remove ¶
func (c *Consistent) Remove(cache Node, weigth int)
Remove removes an element from the hash.
func (*Consistent) Set ¶
func (c *Consistent) Set(caches []Node)
Set sets all the elements in the hash. If there are existing elements not present in elts, they will be removed.
func (*Consistent) SetNumberOfReplicas ¶
func (c *Consistent) SetNumberOfReplicas(num int)