Documentation ¶
Overview ¶
Package memc provides a modern memcached client for Go.
Index ¶
- Variables
- func Add[T any](c *Client, key string, item T, opts ...Option) error
- func Decrement[T Countable](c *Client, key string, delta T) (T, error)
- func Delete(c *Client, key string) error
- func Get[T any](c *Client, key string) (T, error)
- func Increment[T Countable](c *Client, key string, delta T) (T, error)
- func Set[T any](c *Client, key string, item T, opts ...Option) error
- type Client
- type ClientOption
- type Countable
- type Option
- type Options
Constants ¶
This section is empty.
Variables ¶
var ( ErrCacheMiss = errors.New("memc: cache miss") ErrKeyNotValid = errors.New("memc: key is not valid") ErrNotStored = errors.New("memc: item not stored") ErrNotFound = errors.New("memc: item not found") ErrConflict = errors.New("memc: CAS conflict") ErrExpiration = errors.New("memc: expiration ttl is not valid") ErrClientClosed = errors.New("memc: client has been closed") ErrNegativeInc = errors.New("memc: increment delta must be non-negative") ErrNonNumeric = errors.New("memc: cannot increment non-numeric value") )
Functions ¶
func Add ¶
Add will store the item using the given key, but only if no item currently exists. New items are at the top of the LRU.
Uses Client c to connect to a memcached instance, and automatically handles connection pooling and reuse.
One or more Option(s) may be applied to configure things such as the value expiration TTL or its associated flags.
func Decrement ¶
Decrement will decrement the value associated with the given key by delta.
Note: the value must be an ASCII integer. It must have been initially stored as a string value, e.g. by using Set. The delta value must be positive.
Set(client, "counter", "100") Decrement(client, "counter", 1) // counter = 99
func Delete ¶
Delete will remove the value associated with key from memcached.
Uses Client c to connect to a memcached instance, and automatically handles connection pooling and reuse.
func Get ¶
Get the value associated with the given key.
Uses Client c to connect to a memcached instance, and automatically handles connection pooling and reuse.
func Increment ¶
Increment will increment the value associated with the given key by delta.
Note: the value must be an ASCII integer. It must have been initially stored as a string value, e.g. by using Set. The delta value must be positive.
Set(client, "counter", "100") Increment(client, "counter", 1) // counter = 101
func Set ¶
Set will store the item using the given key, possibly overwriting any existing data. New items are at the top of the LRU.
Uses Client c to connect to a memcached instance, and automatically handles connection pooling and reuse.
One or more Option(s) may be applied to configure things such as the value expiration TTL or its associated flags.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
A Client is used for making network requests to memcached instances.
Use the package functions Set, Get, Delete, etc. by providing this Client to manage data in memcached.
func New ¶
func New(instances []string, opts ...ClientOption) *Client
New creates a new Client capable of sharding across the given set of instances and pooling connections to each instance.
Certain behaviors can be configured by specifying one or more ClientOption options.
type ClientOption ¶
type ClientOption func(c *Client)
func SetDefaultTTL ¶
func SetDefaultTTL(expiration time.Duration) ClientOption
SetDefaultTTL adjusts the default expiration time of values set into the memcached instance(s).
If unset the default expiration TTL is 1 hour.
The expiration time must be more than 1 second, or set to 0 to indicate no expiration time (and values stay in the cache indefinitely).
func SetDialTimeout ¶
func SetDialTimeout(timeout time.Duration) ClientOption
SetDialTimeout adjusts the amount of time to wait on establishing a TCP connection to the memached instance(s).
If unset the default timeout is 5 seconds.
func SetIdleConnections ¶
func SetIdleConnections(count int) ClientOption
SetIdleConnections adjusts the maximum number of idle connections to maintain for each memcached instance.
If unset the default idle connection limit is 1.
Note that idle connections are created on demand, not at startup.
type Countable ¶
Countable represents types that work with Increment and Decrement operations.
Note: memcached does not allow negative values for either operation.