Documentation ¶
Index ¶
- Constants
- Variables
- type Client
- func (client *Client) Add(item *Item) error
- func (client *Client) Append(item *Item) error
- func (client *Client) Cas(item *Item) error
- func (client *Client) ConfigTimeout(cCfgKey C.config_options_t, timeout time.Duration)
- func (client *Client) Decr(key string, delta uint64) (uint64, error)
- func (client *Client) Delete(key string) error
- func (client *Client) DeleteMulti(keys []string) (failedKeys []string, err error)
- func (client *Client) FlushAll() ([]string, error)
- func (client *Client) Get(key string) (*Item, error)
- func (client *Client) GetMulti(keys []string) (rv map[string]*Item, err error)
- func (client *Client) GetRealtimeServerAddressByKey(key string) string
- func (client *Client) GetServerAddressByKey(key string) string
- func (client *Client) Gets(key string) (*Item, error)
- func (client *Client) Incr(key string, delta uint64) (uint64, error)
- func (client *Client) Prepend(item *Item) error
- func (client *Client) Quit() error
- func (client *Client) Replace(item *Item) error
- func (client *Client) Set(item *Item) error
- func (client *Client) SetConnMaxLifetime(d time.Duration)
- func (client *Client) SetConnMaxOpen(maxOpen int)
- func (client *Client) SetMaxRetries(maxRetries int)
- func (client *Client) SetMulti(items []*Item) (failedKeys []string, err error)
- func (client *Client) Stats() (map[string](map[string]string), error)
- func (client *Client) ToggleFlushAllFeature(enabled bool)
- func (client *Client) Touch(key string, expiration int64) error
- func (client *Client) Version() (map[string]string, error)
- type Item
Constants ¶
const ( PollTimeout = C.CFG_POLL_TIMEOUT ConnectTimeout = C.CFG_CONNECT_TIMEOUT RetryTimeout = C.CFG_RETRY_TIMEOUT MaxRetries = C.CFG_MAX_RETRIES )
Configure options
const ( HashMD5 = iota HashFNV1_32 HashFNV1a32 HashCRC32 )
Hash functions
const Author = _Author
Author of the package
const Date = _Date
Date of the package
const DefaultPort = 11211
DefaultPort memcached port
const Email = _Email
Email of the author
const Version = _Version
Version of the package
Variables ¶
var ( // ErrCacheMiss means that a Get failed because the item wasn't present. ErrCacheMiss = errors.New("libmc: cache miss") // ErrCASConflict means that a CompareAndSwap call failed due to the // cached value being modified between the Get and the CompareAndSwap. // If the cached value was simply evicted rather than replaced, // ErrNotStored will be returned instead. ErrCASConflict = errors.New("libmc: compare-and-swap conflict") // ErrNotStored means that a conditional write operation (i.e. Add or // CompareAndSwap) failed because the condition was not satisfied. ErrNotStored = errors.New("libmc: item not stored") // ErrMalformedKey is returned when an invalid key is used. // Keys must be at maximum 250 bytes long, ASCII, and not // contain whitespace or control characters. ErrMalformedKey = errors.New("malformed: key is too long or contains invalid characters") // ErrMemcachedClosed is returned when the memcached connection is // already closing. ErrMemcachedClosed = errors.New("memcached is closed") // ErrBadConn is returned when the connection is out of its maxLifetime, so we decide not to use it. ErrBadConn = errors.New("bad conn") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client struct
func New ¶
func New(servers []string, noreply bool, prefix string, hashFunc int, failover bool, disableLock bool) (client *Client)
New to create a memcached client:
servers: is a list of memcached server addresses. Each address can be in format of hostname[:port] [alias]. port and alias are optional. If port is not given, default port 11211 will be used. alias will be used to compute server hash if given, otherwise server hash will be computed based on host and port (i.e.: If port is not given or it is equal to 11211, host will be used to compute server hash. If port is not equal to 11211, host:port will be used).
noreply: whether to enable memcached's noreply behaviour. default: False
prefix: The key prefix. default: ”
hashFunc: hashing function for keys. possible values: HashMD5, HashFNV1_32, HashFNV1a32, HashCRC32 NOTE: fnv1_32, fnv1a_32, crc_32 implementations in libmc are per each spec, but they're not compatible with corresponding implementions in libmemcached. NOTE: The hashing algorithm for host mapping on continuum is always md5.
failover: Whether to failover to next server when current server is not available. default: False
disableLock: Whether to disable a lock of type sync.Mutex which will be use in every retrieval/storage command. default False.
FIXME(Harry): the disableLock option is not working now, 'cause we've add a connection pool to golibmc.
func (*Client) ConfigTimeout ¶
func (client *Client) ConfigTimeout(cCfgKey C.config_options_t, timeout time.Duration)
ConfigTimeout Keys:
PollTimeout ConnectTimeout RetryTimeout
timeout should of type time.Duration
func (*Client) DeleteMulti ¶
DeleteMulti will delete multi keys at once
func (*Client) FlushAll ¶ added in v1.3.0
FlushAll will flush all memcached servers You must call ToggleFlushAllFeature(True) first to enable this feature.
func (*Client) GetRealtimeServerAddressByKey ¶ added in v1.1.0
GetRealtimeServerAddressByKey will return the address of the memcached server where a key is stored. (Will try to connect to corresponding memcached server and may failover accordingly. ) if no server is avaiable, an empty string will be returned.
func (*Client) GetServerAddressByKey ¶
GetServerAddressByKey will return the address of the memcached server where a key is stored (assume all memcached servers are accessiable and wonot establish any connections. )
func (*Client) Replace ¶
Replace is a storage command, return without error only when the key is not empty
func (*Client) SetConnMaxLifetime ¶ added in v1.2.0
SetConnMaxLifetime sets the maximum amount of time a connection may be reused.
Expired connections may be closed lazily before reuse.
If d <= 0, connections are reused forever.
func (*Client) SetConnMaxOpen ¶ added in v1.2.0
SetConnMaxOpen sets the maximum amount of opening connections.
func (*Client) SetMaxRetries ¶ added in v1.4.1
SetMaxRetries sets the maximum amount of retries.
func (*Client) ToggleFlushAllFeature ¶ added in v1.3.0
Enable/Disable the flush_all feature
type Item ¶
type Item struct { // Key is the Item's key (250 bytes maximum). Key string // Value is the Item's value. Value []byte // Object is the Item's value for use with a Codec. Object interface{} // Flags are server-opaque flags whose semantics are entirely // up to the app. Flags uint32 // Expiration is the cache expiration time, in seconds: either a relative // time from now (up to 1 month), or an absolute Unix epoch time. // Zero means the Item has no expiration time., Expiration int64 // contains filtered or unexported fields }
Item is an item to be got or stored in a memcached server. credits to bradfitz/gomemcache