golibmc

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: May 20, 2021 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PollTimeout    = C.CFG_POLL_TIMEOUT
	ConnectTimeout = C.CFG_CONNECT_TIMEOUT
	RetryTimeout   = C.CFG_RETRY_TIMEOUT
	MaxRetries     = C.CFG_MAX_RETRIES
)

Configure options

View Source
const (
	HashMD5 = iota
	HashFNV1_32
	HashFNV1a32
	HashCRC32
)

Hash functions

View Source
const Author = _Author

Author of the package

View Source
const Date = _Date

Date of the package

View Source
const DefaultPort = 11211

DefaultPort memcached port

View Source
const Email = _Email

Email of the author

View Source
const Version = _Version

Version of the package

Variables

View Source
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 SimpleNew

func SimpleNew(servers []string) (client *Client)

SimpleNew to create a memcached client with default params

func (*Client) Add

func (client *Client) Add(item *Item) error

Add is a storage command, return without error only when the key is empty

func (*Client) Append

func (client *Client) Append(item *Item) error

Append value to an existed key

func (*Client) Cas

func (client *Client) Cas(item *Item) error

Cas is short for Compare And Swap

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) Decr

func (client *Client) Decr(key string, delta uint64) (uint64, error)

Decr will decrease the value in key by delta

func (*Client) Delete

func (client *Client) Delete(key string) error

Delete a key

func (*Client) DeleteMulti

func (client *Client) DeleteMulti(keys []string) (failedKeys []string, err error)

DeleteMulti will delete multi keys at once

func (*Client) FlushAll added in v1.3.0

func (client *Client) FlushAll() ([]string, error)

FlushAll will flush all memcached servers You must call ToggleFlushAllFeature(True) first to enable this feature.

func (*Client) Get

func (client *Client) Get(key string) (*Item, error)

Get is a retrieval command. It will return Item or nil

func (*Client) GetMulti

func (client *Client) GetMulti(keys []string) (rv map[string]*Item, err error)

GetMulti will return a map of multi values

func (*Client) GetRealtimeServerAddressByKey added in v1.1.0

func (client *Client) GetRealtimeServerAddressByKey(key string) string

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

func (client *Client) GetServerAddressByKey(key string) string

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) Gets

func (client *Client) Gets(key string) (*Item, error)

Gets is a retrieval command. It will return Item(with casid) or nil

func (*Client) Incr

func (client *Client) Incr(key string, delta uint64) (uint64, error)

Incr will increase the value in key by delta

func (*Client) Prepend

func (client *Client) Prepend(item *Item) error

Prepend value to an existed key

func (*Client) Quit

func (client *Client) Quit() error

Quit will close the sockets to each memcached server

func (*Client) Replace

func (client *Client) Replace(item *Item) error

Replace is a storage command, return without error only when the key is not empty

func (*Client) Set

func (client *Client) Set(item *Item) error

Set value to a key

func (*Client) SetConnMaxLifetime added in v1.2.0

func (client *Client) SetConnMaxLifetime(d time.Duration)

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

func (client *Client) SetConnMaxOpen(maxOpen int)

SetConnMaxOpen sets the maximum amount of opening connections.

func (*Client) SetMaxRetries added in v1.4.1

func (client *Client) SetMaxRetries(maxRetries int)

SetMaxRetries sets the maximum amount of retries.

func (*Client) SetMulti

func (client *Client) SetMulti(items []*Item) (failedKeys []string, err error)

SetMulti will set multi values at once

func (*Client) Stats

func (client *Client) Stats() (map[string](map[string]string), error)

Stats will return a map reflecting stats map of each memcached server

func (*Client) ToggleFlushAllFeature added in v1.3.0

func (client *Client) ToggleFlushAllFeature(enabled bool)

Enable/Disable the flush_all feature

func (*Client) Touch

func (client *Client) Touch(key string, expiration int64) error

Touch command

func (*Client) Version

func (client *Client) Version() (map[string]string, error)

Version will return a map reflecting versions of each memcached server

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

Jump to

Keyboard shortcuts

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