reconnectingmemcached

package
v0.0.0-...-11f94f5 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package reconnectingmemcached contains a wrapper around a general memcache client. It provides the ability to automatically reconnect after a certain number of failures. While the connection is down, its APIs quickly return, allowing clients to fallback to some other mechanism. This design decision (instead of, for example, blocking until the connection is restored) is because memcached is used where performance is critical, and it is probably faster for clients to respond to a memcached outage like they would a cache miss.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient(opts Options) *healingClientImpl

NewClient returns a Client to talk to memcached instance(s) that will heal and re-generate itself with the options provided.

Types

type Client

type Client interface {
	// ConnectionAvailable returns true if there is an established connection. If false is returned,
	// it means the connection is being restored.
	ConnectionAvailable() bool
	// GetMulti returns a map filled with items that were in the cache. The boolean means "ok"
	// and can be false if either there was an error or the connection is currently down.
	GetMulti(keys []string) (map[string]*memcache.Item, bool)
	// Ping returns an error if there is no connection or if any instance is down.
	Ping() error
	// Set unconditionally sets the item. It returns false if there was an error or the connection
	// is currently down.
	Set(i *memcache.Item) bool
}

Client is a slightly modified version of the interface on *memcache.Client. Most of the methods return a boolean instead of an error. That boolean indicates if the connection is up or down, that is, if the return value is valid or if the calling client should use a fallback.

type Options

type Options struct {
	// Servers are the addresses of the servers that should be contacted with equal weight.
	// See bradfitz/gomemcache/memcache.New() for more.
	Servers []string
	// Timeout is the socket read/write timeout. The default is 100 milliseconds.
	Timeout time.Duration
	// MaxIdleConnections is the maximum number of connections. It should be greater than or
	// equal to the peek parallel requests. The default is 2.
	MaxIdleConnections int

	// AllowedFailuresBeforeHealing is the number of connection errors that will be tolerated
	// before autohealing starts.
	AllowedFailuresBeforeHealing int
}

Jump to

Keyboard shortcuts

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