ketama

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2020 License: GPL-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package ketama provides libmemcached-compatible consistent hashing. That means that you can use memcached from go as well as from any libmemcached based library and have same keys go to the same nodes in your cluster.

It is designed with github.com/bradfitz/gomemcache/memcache package in mind, by implementing memcache.ServerSelector interface it is drop-in replacement for memcache.ServerList.

Usage could look something like this:

k := &ketama.Ketama{}
k.SetServersAddr([]net.Addr{&net.TCPAddr{
	IP: net.ParseIP("127.0.0.1"),
	Port: 11211,
}})

mc := memcache.NewFromSelector(k)
fmt.Println(mc.Get("some-key"))

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNegativeWeight = errors.New("negative weight is not allowed")
)

Functions

This section is empty.

Types

type Ketama

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

Ketama provides ketama-based server list. It is core stucture of this package.

func (*Ketama) Each

func (k *Ketama) Each(fn func(net.Addr) error) error

Each calls fn with every address that is currently registered into this server list.

func (*Ketama) PickServer

func (k *Ketama) PickServer(key string) (net.Addr, error)

PickServer returns address onto which the key should go. Matches libmemcached in it's selection (that is whole point of this package). Safe to call from multiple goroutines at once.

func (*Ketama) SetServers

func (k *Ketama) SetServers(servers []Server) error

SetServers updates current list of server to servers. It is safe to call from multiple goroutines at once.

func (*Ketama) SetServersAddr

func (k *Ketama) SetServersAddr(addrs []net.Addr) error

SetServers updates current list of server to addrs. All addresses have weight of 1. It is safe to call from multiple goroutines at once.

type Server

type Server struct {
	// Addr of the server. net.TCPAddr, net.UDPAddr and net.UnixAddr are
	// supported types.
	Addr net.Addr
	// Weight this server should have. Must be >= 0. To mirror
	// libmemcached's behavior, 0 is considered same as 1.
	Weight int
}

Server holds details about single server.

Jump to

Keyboard shortcuts

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