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 ¶
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 ¶
Each calls fn with every address that is currently registered into this server list.
func (*Ketama) PickServer ¶
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 ¶
SetServers updates current list of server to servers. 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.