Documentation ¶
Index ¶
- func NewMemcachedClient(logger log.Logger, name string, conf []byte, reg prometheus.Registerer) (*memcachedClient, error)
- func NewMemcachedClientWithConfig(logger log.Logger, name string, config MemcachedClientConfig, ...) (*memcachedClient, error)
- type AddressProvider
- type MemcachedClient
- type MemcachedClientConfig
- type MemcachedJumpHashSelector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewMemcachedClient ¶
func NewMemcachedClient(logger log.Logger, name string, conf []byte, reg prometheus.Registerer) (*memcachedClient, error)
NewMemcachedClient makes a new MemcachedClient.
func NewMemcachedClientWithConfig ¶
func NewMemcachedClientWithConfig(logger log.Logger, name string, config MemcachedClientConfig, reg prometheus.Registerer) (*memcachedClient, error)
NewMemcachedClientWithConfig makes a new MemcachedClient.
Types ¶
type AddressProvider ¶ added in v0.23.0
type AddressProvider interface { // Resolves the provided list of memcached cluster to the actual nodes Resolve(context.Context, []string) error // Returns the nodes Addresses() []string }
AddressProvider performs node address resolution given a list of clusters.
type MemcachedClient ¶
type MemcachedClient interface { // GetMulti fetches multiple keys at once from memcached. In case of error, // an empty map is returned and the error tracked/logged. GetMulti(ctx context.Context, keys []string) map[string][]byte // SetAsync enqueues an asynchronous operation to store a key into memcached. // Returns an error in case it fails to enqueue the operation. In case the // underlying async operation will fail, the error will be tracked/logged. SetAsync(ctx context.Context, key string, value []byte, ttl time.Duration) error // Stop client and release underlying resources. Stop() }
MemcachedClient is a high level client to interact with memcached.
type MemcachedClientConfig ¶
type MemcachedClientConfig struct { // Addresses specifies the list of memcached addresses. The addresses get // resolved with the DNS provider. Addresses []string `yaml:"addresses"` // Timeout specifies the socket read/write timeout. Timeout time.Duration `yaml:"timeout"` // MaxIdleConnections specifies the maximum number of idle connections that // will be maintained per address. For better performances, this should be // set to a number higher than your peak parallel requests. MaxIdleConnections int `yaml:"max_idle_connections"` // MaxAsyncConcurrency specifies the maximum number of SetAsync goroutines. MaxAsyncConcurrency int `yaml:"max_async_concurrency"` // MaxAsyncBufferSize specifies the queue buffer size for SetAsync operations. MaxAsyncBufferSize int `yaml:"max_async_buffer_size"` // MaxGetMultiConcurrency specifies the maximum number of concurrent GetMulti() operations. // If set to 0, concurrency is unlimited. MaxGetMultiConcurrency int `yaml:"max_get_multi_concurrency"` // MaxItemSize specifies the maximum size of an item stored in memcached. // Items bigger than MaxItemSize are skipped. // If set to 0, no maximum size is enforced. MaxItemSize model.Bytes `yaml:"max_item_size"` // MaxGetMultiBatchSize specifies the maximum number of keys a single underlying // GetMulti() should run. If more keys are specified, internally keys are splitted // into multiple batches and fetched concurrently, honoring MaxGetMultiConcurrency parallelism. // If set to 0, the max batch size is unlimited. MaxGetMultiBatchSize int `yaml:"max_get_multi_batch_size"` // DNSProviderUpdateInterval specifies the DNS discovery update interval. DNSProviderUpdateInterval time.Duration `yaml:"dns_provider_update_interval"` // AutoDiscovery configures memached client to perform auto-discovery instead of DNS resolution AutoDiscovery bool `yaml:"auto_discovery"` }
MemcachedClientConfig is the config accepted by MemcachedClient.
type MemcachedJumpHashSelector ¶
type MemcachedJumpHashSelector struct {
// contains filtered or unexported fields
}
MemcachedJumpHashSelector implements the memcache.ServerSelector interface, utilizing 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, MemcachedJumpHashSelector works best for servers with consistent DNS names where the naturally sorted order is predictable (ie. Kubernetes statefulsets).
func (*MemcachedJumpHashSelector) Each ¶
func (s *MemcachedJumpHashSelector) Each(f func(net.Addr) error) error
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 (*MemcachedJumpHashSelector) PickServer ¶
func (s *MemcachedJumpHashSelector) PickServer(key string) (net.Addr, error)
PickServer returns the server address that a given item should be shared onto.
func (*MemcachedJumpHashSelector) SetServers ¶
func (s *MemcachedJumpHashSelector) SetServers(servers ...string) error
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.