Documentation ¶
Index ¶
- type Selector
- func (s *Selector) Addrs() []net.Addr
- func (s *Selector) Each(f func(net.Addr) error) error
- func (s *Selector) FromString(key string) (net.Addr, error)
- func (s *Selector) FromUInt64(key uint64) (net.Addr, error)
- func (s *Selector) PickServer(key string) (net.Addr, error)
- func (s *Selector) SetServers(servers ...string) error
- type TCPResolver
- type UnixResolver
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Selector ¶
type Selector struct {
// contains filtered or unexported fields
}
Selector implements the memcache.ServerSelector interface. Selector utilizes a jump hash to distribute keys to servers.
While adding or removing servers only requires 1/N keys to move, servers are treated as a stack and can only be pushed/popped. Therefore, Selector works best for servers with consistent DNS names where the naturally sorted order is predictable.
func DefaultSelector ¶
func DefaultSelector() *Selector
func NewSelector ¶
func NewSelector(resolveUnixAddr UnixResolver, resolveTCPAddr TCPResolver) *Selector
func (*Selector) Each ¶
Each iterates over each server and calls the given function. If f returns a non-nil error, iteration will stop and that error will be returned.
func (*Selector) PickServer ¶
PickServer returns the server address that a given item should be shared onto.
func (*Selector) SetServers ¶
SetServers changes a MemcachedJumpHashSelector's set of servers at runtime and is safe for concurrent use by multiple goroutines.
Each server is given equal weight. A server is given more weight if it's listed multiple times.
SetServers returns an error if any of the server names fail to resolve. No attempt is made to connect to the server. If any error occurs, no changes are made to the internal server list.
To minimize the number of rehashes for keys when scaling the number of servers in subsequent calls to SetServers, servers are stored in natural sort order.