Documentation ¶
Overview ¶
Package mc is a memcache client for Go supporting binary protocol and SASL authentication.
Index ¶
- Constants
- Variables
- func NewModuloHasher() hasher
- type Client
- func (c *Client) Add(key, val string, flags, exp uint32) (cas uint64, err error)
- func (c *Client) Append(key, val string, ocas uint64) (cas uint64, err error)
- func (c *Client) Decr(key string, delta, init uint64, exp uint32, ocas uint64) (n, cas uint64, err error)
- func (c *Client) Del(key string) (err error)
- func (c *Client) DelCAS(key string, cas uint64) (err error)
- func (c *Client) Flush(when uint32) (err error)
- func (c *Client) GAT(key string, exp uint32) (val string, flags uint32, cas uint64, err error)
- func (c *Client) Get(key string) (val string, flags uint32, cas uint64, err error)
- func (c *Client) Incr(key string, delta, init uint64, exp uint32, ocas uint64) (n, cas uint64, err error)
- func (c *Client) NoOp() (err error)
- func (c *Client) Prepend(key, val string, ocas uint64) (cas uint64, err error)
- func (c *Client) Quit()
- func (c *Client) Replace(key, val string, flags, exp uint32, ocas uint64) (cas uint64, err error)
- func (c *Client) Set(key, val string, flags, exp uint32, ocas uint64) (cas uint64, err error)
- func (c *Client) Stats() (stats map[string]McStats, err error)
- func (c *Client) StatsReset() (err error)
- func (c *Client) StatsWithKey(key string) (map[string]McStats, error)
- func (c *Client) Touch(key string, exp uint32) (cas uint64, err error)
- func (c *Client) Version() (vers map[string]string, err error)
- type Config
- type Error
- type McStats
Constants ¶
const ( StatusOK = uint16(0) StatusNotFound = uint16(1) StatusKeyExists = uint16(2) StatusValueTooLarge = uint16(3) StatusInvalidArgs = uint16(4) StatusValueNotStored = uint16(5) StatusNonNumeric = uint16(6) StatusAuthRequired = uint16(0x20) StatusAuthContinue = uint16(0x21) StatusUnknownCommand = uint16(0x81) StatusOutOfMemory = uint16(0x82) StatusAuthUnknown = uint16(0xffff) StatusNetworkError = uint16(0xfff1) StatusUnknownError = uint16(0xffff) )
Status Codes that may be returned (usually as part of an Error).
Variables ¶
var ( ErrNotFound = &Error{StatusNotFound, "mc: not found", nil} ErrKeyExists = &Error{StatusKeyExists, "mc: key exists", nil} ErrValueTooLarge = &Error{StatusValueNotStored, "mc: value to large", nil} ErrInvalidArgs = &Error{StatusInvalidArgs, "mc: invalid arguments", nil} ErrValueNotStored = &Error{StatusValueNotStored, "mc: value not stored", nil} ErrNonNumeric = &Error{StatusNonNumeric, "mc: incr/decr called on non-numeric value", nil} ErrAuthRequired = &Error{StatusAuthRequired, "mc: authentication required", nil} ErrAuthContinue = &Error{StatusAuthContinue, "mc: authentication continue (unsupported)", nil} ErrUnknownCommand = &Error{StatusUnknownCommand, "mc: unknown command", nil} ErrOutOfMemory = &Error{StatusOutOfMemory, "mc: out of memory", nil} ErrUnknownError = &Error{StatusUnknownError, "mc: unknown error from server", nil} )
Errors mc may return. Some errors aren't represented here as the message is dynamically generated. Status Code however captures all possible values for Error.Status.
Functions ¶
func NewModuloHasher ¶
func NewModuloHasher() hasher
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a memcached client that is connected to a list of servers
func NewMC ¶
NewMC creates a new client with the default configuration. For the default configuration see DefaultConfig.
func NewMCwithConfig ¶
NewMCwithConfig creates a new client for a given configuration
func (*Client) Add ¶
Add adds a new key/value to the cache. Fails if the key already exists in the cache.
func (*Client) Append ¶
Append appends the value to the existing value for the key specified. An error is thrown if the key doesn't exist.
func (*Client) Decr ¶
func (c *Client) Decr(key string, delta, init uint64, exp uint32, ocas uint64) (n, cas uint64, err error)
Decr decrements a value in the cache. The value must be an unsigned 64bit integer stored as an ASCII string. It can't be decremented below 0.
func (*Client) DelCAS ¶
DelCAS deletes a key/value from the cache but only if the CAS specified matches the CAS in the cache.
func (*Client) Flush ¶
Flush flushes the cache, that is, invalidate all keys. Note, this doesn't typically free memory on a memcache server (doing so compromises the O(1) nature of memcache). Instead nearly all servers do lazy expiration, where they don't free memory but won't return any keys to you that have expired.
func (*Client) GAT ¶
GAT (get and touch) retrieves the value associated with the key and updates its expiration time.
func (*Client) Incr ¶
func (c *Client) Incr(key string, delta, init uint64, exp uint32, ocas uint64) (n, cas uint64, err error)
Incr increments a value in the cache. The value must be an unsigned 64bit integer stored as an ASCII string. It will wrap when incremented outside the range.
func (*Client) NoOp ¶
NoOp sends a No-Op message to the memcache server. This can be used as a heartbeat for the server to check it's functioning fine still.
func (*Client) Prepend ¶
Prepend prepends the value to the existing value for the key specified. An error is thrown if the key doesn't exist.
func (*Client) Quit ¶
func (c *Client) Quit()
Quit closes the connection with memcached server (nicely).
func (*Client) Replace ¶
Replace replaces an existing key/value in the cache. Fails if key doesn't already exist in cache.
func (*Client) StatsReset ¶
StatsReset resets the statistics stored at the memcached server.
func (*Client) StatsWithKey ¶
StatsWithKey returns some statistics about the memcached server. It supports sending across a key to the server to select which statistics should be returned.
type Config ¶
type Config struct { Hasher hasher Retries int RetryDelay time.Duration Failover bool // ConnectionTimeout is currently used to timeout getting connections from // pool, as a sending deadline and as a reading deadline. Worst case this // means a request can take 3 times the ConnectionTimeout. ConnectionTimeout time.Duration DownRetryDelay time.Duration PoolSize int TcpKeepAlive bool TcpKeepAlivePeriod time.Duration TcpNoDelay bool }
Config holds the Memcache client configuration. Use DefaultConfig to get an initialized version.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a config object populated with the default values. The default values currently are:
config{ Hasher: NewModuloHasher(), Retries: 2, RetryDelay: 200 * time.Millisecond, Failover: true, ConnectionTimeout: 2 * time.Second, DownRetryDelay: 60 * time.Second, PoolSize: 1, TcpKeepAlive: true, TcpKeepAlivePeriod: 60 * time.Second, TcpNoDelay: true, }
type Error ¶
Error represents a MemCache error (including the status code). All function in mc return error values of this type, despite the functions using the plain error type. You can safely cast all error types returned by mc to *Error. If needed, we take an underlying error value (such as a network error) and wrap it in Error, storing the underlying value in WrappedError.
error is used as the return typed instead of Error directly due to the limitation in Go where error(nil) != *Error(nil).