Documentation ¶
Overview ¶
Package memcacheha wraps github.com/bradfitz/gomemcache/memcache to provide HA (highly available) functionality with lazy client-side synchronization.
Index ¶
- Constants
- Variables
- type Client
- func (client *Client) Add(item *Item) error
- func (client *Client) Delete(key string) error
- func (client *Client) Get(key string) (*Item, error)
- func (client *Client) GetNodes()
- func (client *Client) HealthCheck() error
- func (client *Client) Set(item *Item) error
- func (client *Client) Start() error
- func (client *Client) Stop() error
- func (client *Client) Touch(key string, seconds int32) error
- func (client *Client) WaitForNodes(deadline time.Time) error
- type ElastiCacheNodeSource
- type Item
- type Logger
- type Node
- func (node *Node) Add(item *Item, finishChan chan (*NodeResponse))
- func (node *Node) Delete(key string, finishChan chan (*NodeResponse))
- func (node *Node) Get(key string, finishChan chan (*NodeResponse))
- func (node *Node) HealthCheck() (bool, error)
- func (node *Node) Set(item *Item, finishChan chan (*NodeResponse))
- func (node *Node) Touch(key string, seconds int32, finishChan chan (*NodeResponse))
- type NodeList
- type NodeResponse
- type NodeSource
- type StaticNodeSource
Constants ¶
const (
// ELASTICACHE_ENGINE_MEMCACHE is the AWS Engine type for a memcached cluster
ELASTICACHE_ENGINE_MEMCACHE = "memcached"
)
const VERSION = "0.1.0"
VERSION is the version of this memcacheha client
Variables ¶
var ( // GET_NODES_PERIOD is the period between checking all sources for new or deprecated nodes GET_NODES_PERIOD = 10 * time.Second // HEALTHCHECK_PERIOD is the period between healthchecks on nodes HEALTHCHECK_PERIOD = 5 * time.Second )
var ( // ErrElastiCacheMultipleClusters is an error meaning that the AWS discovery call returned more than one cluster ErrElastiCacheMultipleClusters = errors.New("DescribeCacheClusters returned more than one cluster") // ErrElastiCacheNotMemcache is an error meaning that the AWS discovery call returned a cluster that is not a memcached cluster ErrElastiCacheNotMemcache = errors.New("Not a memcache cluster") )
var ( // ErrNotRunning is an error meaning Stop has been called on a client that is not running ErrNotRunning = errors.New("memcacheha: not running") // ErrAlreadyRunning is an error meaning Start has been called on a client that is already running ErrAlreadyRunning = errors.New("memcacheha: already running") // ErrNoHealthyNodes is an error meaning there are no nodes that can be contacted ErrNoHealthyNodes = errors.New("memcacheha: no healthy nodes") // ErrUnknown represents an internal panic() ErrUnknown = errors.New("memcacheha: unknown error occurred") )
var ErrNotMemcacheHAKey = errors.New("not a memcacheha key")
var MEMCACHEHA_HEADER []byte = []byte{0xfd, 0x37, 0xd3, 0x1b}
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { Nodes *NodeList Sources []NodeSource Log Logger Timeout time.Duration // contains filtered or unexported fields }
Client represents the cluster client.
func New ¶
func New(logger Logger, sources ...NodeSource) *Client
New returns a new Client with the specified logger and NodeSources
func (*Client) Add ¶
Add writes the given item, if no value already exists for its key. ErrNotStored is returned if that condition is not met.
func (*Client) Delete ¶
Delete deletes the item with the provided key. The error ErrCacheMiss is returned if the item didn't already exist in the cache.
func (*Client) Get ¶
Get gets the item for the given key. ErrCacheMiss is returned for a memcache cache miss. The key must be at most 250 bytes in length.
func (*Client) GetNodes ¶
func (client *Client) GetNodes()
GetNodes updates the list of nodes in the client from the configured sources.
func (*Client) HealthCheck ¶
HealthCheck performs a healthcheck on all nodes.
func (*Client) Start ¶
Start the Client client. This should be called before any operations are called.
func (*Client) Touch ¶
Touch updates the expiry for the given key. The seconds parameter is either a Unix timestamp or, if seconds is less than 1 month, the number of seconds into the future at which time the item will expire. ErrCacheMiss is returned if the key is not in the cache. The key must be at most 250 bytes in length.
type ElastiCacheNodeSource ¶
ElastiCacheNodeSource represents a source of nodes from an AWS ElastiCache cluster
func NewElastiCacheNodeSource ¶
func NewElastiCacheNodeSource(log Logger, awsRegion string, cacheClusterId string) *ElastiCacheNodeSource
NewElastiCacheNodeSource returns a new ElastiCacheNodeSource with the given logger, AWS region, and cache cluster ID
func (*ElastiCacheNodeSource) GetNodes ¶
func (elastiCacheNodeSource *ElastiCacheNodeSource) GetNodes() ([]string, error)
GetNodes implements NodeSource, querying the AWS API to get the nodes in the configured CacheClusterId
type Item ¶
type Item struct { // Key is the Item's key (250 bytes maximum). Key string // Value is the Item's value. Value []byte // Flags are server-opaque flags whose semantics are entirely // up to the app. Flags uint32 // Expiration is either nil (no expiry) or an absolute expiry time Expiration *time.Time }
func (*Item) AsMemcacheItem ¶
type Logger ¶
type Logger interface { Error(message string, args ...interface{}) Warn(message string, args ...interface{}) Info(message string, args ...interface{}) Debug(message string, args ...interface{}) }
Logger defines what is expected of the passed in logger
type Node ¶
type Node struct { Endpoint string Log Logger IsHealthy bool LastHealthCheck time.Time // contains filtered or unexported fields }
Node represents a single Memcache server.
func (*Node) Add ¶
func (node *Node) Add(item *Item, finishChan chan (*NodeResponse))
Add an item to the memcache server represented by this node and send the response to the given channel
func (*Node) Delete ¶
func (node *Node) Delete(key string, finishChan chan (*NodeResponse))
Delete an item with the given key from the memcache server represented by this node and send the response to the given channel
func (*Node) Get ¶
func (node *Node) Get(key string, finishChan chan (*NodeResponse))
Get an item with the given key from the memcache server represented by this node and send the response to the given channel
func (*Node) HealthCheck ¶
HealthCheck performs a healthcheck on the memcache server represented by this node, update IsHealthy, and return it
func (*Node) Set ¶
func (node *Node) Set(item *Item, finishChan chan (*NodeResponse))
Set an item in the memcache server represented by this node and send the response to the given channel
type NodeList ¶
NodeList represents a list of memcache servers configured/discovered by this client.
func (*NodeList) GetHealthyNodeCount ¶
GetHealthyNodeCount returns the count of Nodes where the node IsHealthy is true
func (*NodeList) GetHealthyNodes ¶
GetHealthyNodes returns a map of config endpoints to Nodes where the node IsHealthy is true
type NodeResponse ¶
NodeResponse represents a reply from a node
func NewNodeResponse ¶
func NewNodeResponse(node *Node, item *Item, err error) *NodeResponse
NewNodeResponse returns a new NodeResponse with the specified Node, Item and Error
type NodeSource ¶
NodeSource is an interface defining the GetNodes function. All node sources must implement NodeSource.
type StaticNodeSource ¶
type StaticNodeSource []string
StaticNodeSource represents a static list of nodes
func NewStaticNodeSource ¶
func NewStaticNodeSource(nodes ...string) *StaticNodeSource
NewStaticNodeSource returns a new StaticNodeSource with the given endpoints
func (*StaticNodeSource) GetNodes ¶
func (staticNodeSource *StaticNodeSource) GetNodes() ([]string, error)
GetNodes implements NodeSource, return a slice of configured endpoints