Documentation

Overview

    A generic memcache client library which supports connection pooling and flexible sharding.

    Implementation note: this client uses memcached's binary protocol. See https://code.google.com/p/memcached/wiki/BinaryProtocolRevamped for additional details.

    Index

    Examples

    Constants

    View Source
    const (
    	ActiveServer    = MemcachedState(0)
    	WriteOnlyServer = MemcachedState(1)
    	DownServer      = MemcachedState(2)
    	WarmUpServer    = MemcachedState(4)
    )

    Variables

    This section is empty.

    Functions

    func NewStatusCodeError

    func NewStatusCodeError(status ResponseStatus) error

    Types

    type BaseShardManager

    type BaseShardManager struct {
    	// contains filtered or unexported fields
    }

      A base shard manager implementation that can be used to implement other shard managers.

      func (*BaseShardManager) GetAllShards

      func (m *BaseShardManager) GetAllShards() map[int]net2.ManagedConn

        See ShardManager interface for documentation.

        func (*BaseShardManager) GetShard

        func (m *BaseShardManager) GetShard(
        	key string) (
        	shardId int,
        	conn net2.ManagedConn,
        	err error)

          See ShardManager interface for documentation.

          func (*BaseShardManager) GetShardsForItems

          func (m *BaseShardManager) GetShardsForItems(
          	items []*Item) map[int]*ShardMapping

            See ShardManager interface for documentation.

            func (*BaseShardManager) GetShardsForKeys

            func (m *BaseShardManager) GetShardsForKeys(
            	keys []string) map[int]*ShardMapping

              See ShardManager interface for documentation.

              func (*BaseShardManager) GetShardsForSentinelsFromItems

              func (m *BaseShardManager) GetShardsForSentinelsFromItems(
              	items []*Item) map[int]*ShardMapping

                See ShardManager interface for documentation.

                func (*BaseShardManager) GetShardsForSentinelsFromKeys

                func (m *BaseShardManager) GetShardsForSentinelsFromKeys(
                	keys []string) map[int]*ShardMapping

                  See ShardManager interface for documentation.

                  func (*BaseShardManager) Init

                  func (m *BaseShardManager) Init(
                  	shardFunc func(key string, numShard int) (shard int),
                  	logError func(err error),
                  	logInfo func(v ...interface{}),
                  	options net2.ConnectionOptions)

                    Initializes the BaseShardManager.

                    func (*BaseShardManager) InitWithPool

                    func (m *BaseShardManager) InitWithPool(
                    	shardFunc func(key string, numShard int) (shard int),
                    	logError func(err error),
                    	logInfo func(v ...interface{}),
                    	pool net2.ConnectionPool)

                    func (*BaseShardManager) UpdateShardStates

                    func (m *BaseShardManager) UpdateShardStates(shardStates []ShardState)

                      This updates the shard manager to use new shard states.

                      type Client

                      type Client interface {
                      	// This retrieves a single entry from memcache.
                      	Get(key string) GetResponse
                      
                      	// Batch version of the Get method.
                      	GetMulti(keys []string) map[string]GetResponse
                      
                      	// *** This method is specific to Dropbox zookeeper-managed memcache ***
                      	// This is the same as GetMulti.  The only difference is that GetMulti will
                      	// only read from ACTIVE memcache shards, while GetSentinels will read from
                      	// both ACTIVE and WRITE_ONLY memcache shards.
                      	GetSentinels(keys []string) map[string]GetResponse
                      
                      	// This sets a single entry into memcache.  If the item's data version id
                      	// (aka CAS) is nonzero, the set operation can only succeed if the item
                      	// exists in memcache and has a same data version id; otherwise, this will
                      	// do an unconditional set.
                      	Set(item *Item) MutateResponse
                      
                      	// Batch version of the Set method.  Note that the response entries
                      	// ordering is undefined (i.e., may not match the input ordering).
                      	SetMulti(items []*Item) []MutateResponse
                      
                      	// *** This method is specific to Dropbox zookeeper-managed memcache ***
                      	// This is the same as SetMulti.  The only difference is that SetMulti will
                      	// only write to ACTIVE memcache shards, while SetSentinels will write to
                      	// both ACTIVE and WRITE_ONLY memcache shards.
                      	SetSentinels(items []*Item) []MutateResponse
                      
                      	// Just like SetMulti, but if item's data version id (aka CAS) is zero,
                      	// it will do a **conditional** add (will fail if the item already exists
                      	// in memcache).
                      	CasMulti(items []*Item) []MutateResponse
                      
                      	// *** This method is specific to Dropbox zookeeper-managed memcache ***
                      	// This is the same as CasMulti.  The only difference is that CasMulti will
                      	// only write to ACTIVE memcache shards, while CasSentinels will write to
                      	// both ACTIVE and WRITE_ONLY memcache shards.
                      	CasSentinels(items []*Item) []MutateResponse
                      
                      	// This adds a single entry into memcache.  Note: Add will fail if the
                      	// item already exist in memcache.
                      	Add(item *Item) MutateResponse
                      
                      	// Batch version of the Add method.  Note that the response entries
                      	// ordering is undefined (i.e., may not match the input ordering).
                      	AddMulti(item []*Item) []MutateResponse
                      
                      	// This replaces a single entry in memcache.  Note: Replace will fail if
                      	// the does not exist in memcache.
                      	Replace(item *Item) MutateResponse
                      
                      	// This delets a single entry from memcache.
                      	Delete(key string) MutateResponse
                      
                      	// Batch version of the Delete method.  Note that the response entries
                      	// ordering is undefined (i.e., may not match the input ordering)
                      	DeleteMulti(keys []string) []MutateResponse
                      
                      	// This appends the value bytes to the end of an existing entry.  Note that
                      	// this does not allow you to extend past the item limit.
                      	Append(key string, value []byte) MutateResponse
                      
                      	// This prepends the value bytes to the end of an existing entry.  Note that
                      	// this does not allow you to extend past the item limit.
                      	Prepend(key string, value []byte) MutateResponse
                      
                      	// This increments the key's counter by delta.  If the counter does not
                      	// exist, one of two things may happen:
                      	// 1. If the expiration value is all one-bits (0xffffffff), the operation
                      	//    will fail with StatusNotFound.
                      	// 2. For all other expiration values, the operation will succeed by
                      	//    seeding the value for this key with the provided initValue to expire
                      	//    with the provided expiration time. The flags will be set to zero.
                      	//
                      	// NOTE:
                      	// 1. If you want to set the value of the counter with add/set/replace,
                      	//    the objects data must be the ascii representation of the value and
                      	//    not the byte values of a 64 bit integer.
                      	// 2. Incrementing the counter may cause the counter to wrap.
                      	Increment(
                      		key string,
                      		delta uint64,
                      		initValue uint64,
                      		expiration uint32) CountResponse
                      
                      	// This decrements the key's counter by delta.  If the counter does not
                      	// exist, one of two things may happen:
                      	// 1. If the expiration value is all one-bits (0xffffffff), the operation
                      	//    will fail with StatusNotFound.
                      	// 2. For all other expiration values, the operation will succeed by
                      	//    seeding the value for this key with the provided initValue to expire
                      	//    with the provided expiration time. The flags will be set to zero.
                      	//
                      	// NOTE:
                      	// 1. If you want to set the value of the counter with add/set/replace,
                      	//    the objects data must be the ascii representation of the value and
                      	//    not the byte values of a 64 bit integer.
                      	// 2. Decrementing a counter will never result in a "negative value" (or
                      	//    cause the counter to "wrap"). instead the counter is set to 0.
                      	Decrement(
                      		key string,
                      		delta uint64,
                      		initValue uint64,
                      		expiration uint32) CountResponse
                      
                      	// This invalidates all existing cache items after expiration number of
                      	// seconds.
                      	Flush(expiration uint32) Response
                      
                      	// This requests the server statistics. When the key is an empty string,
                      	// the server will respond with a "default" set of statistics information.
                      	Stat(statsKey string) StatResponse
                      
                      	// This returns the server's version string.
                      	Version() VersionResponse
                      
                      	// This set the verbosity level of the server.
                      	Verbosity(verbosity uint32) Response
                      }

                        NOTE(mihnea) - ideally we should be able to separate methods that are state-aware (i.e. GetSentinels / SetSentinels) away from this interface and into a new interface (e.g. StateAwareClient / ConsistentCachingClient). Such an interface should also have fewer methods (e.g. no Increment, Flush, etc.)

                        func NewMockClient

                        func NewMockClient() Client

                        func NewMockClientErrorAllSets

                        func NewMockClientErrorAllSets() Client

                        func NewMockClientFailEverything

                        func NewMockClientFailEverything() Client

                        func NewMockClientMissAllGets

                        func NewMockClientMissAllGets() Client

                        func NewShardedClient

                        func NewShardedClient(
                        	manager ShardManager,
                        	builder ClientShardBuilder) Client

                          This creates a new ShardedClient.

                          type ClientShard

                          type ClientShard interface {
                          	Client
                          
                          	// This returns the memcache server's shard id.
                          	ShardId() int
                          
                          	// This returns true if the client is in a valid state.  If the client is
                          	// in invalid state, the user should abandon the current client / channel,
                          	// and create a new client / channel as replacment.
                          	IsValidState() bool
                          }

                            A memcache client which communicates with a specific memcache shard.

                            func NewLargeRawBinaryClient

                            func NewLargeRawBinaryClient(shard int, channel io.ReadWriter) ClientShard

                              This creates a new memcache RawBinaryClient for use with np-large cluster.

                              func NewRawAsciiClient

                              func NewRawAsciiClient(shard int, channel io.ReadWriter) ClientShard

                                This creates a new memcache RawAsciiClient.

                                func NewRawBinaryClient

                                func NewRawBinaryClient(shard int, channel io.ReadWriter) ClientShard

                                  This creates a new memcache RawBinaryClient.

                                  type ClientShardBuilder

                                  type ClientShardBuilder func(shard int, channel io.ReadWriter) ClientShard

                                    The ClientShardBuilder creates ClientShard by shard id and connection.

                                    type CountResponse

                                    type CountResponse interface {
                                    	Response
                                    
                                    	// This returns the input key (useful for SetMulti where operations may be
                                    	// applied out of order).
                                    	Key() string
                                    
                                    	// This returns the resulting count value.  On error status, this returns
                                    	// zero.
                                    	Count() uint64
                                    }

                                      Response returned by Increment/Decrement requests.

                                      func NewCountErrorResponse

                                      func NewCountErrorResponse(key string, err error) CountResponse

                                        This creates a CountResponse from an error.

                                        func NewCountResponse

                                        func NewCountResponse(
                                        	key string,
                                        	status ResponseStatus,
                                        	count uint64) CountResponse

                                          This creates a normal CountResponse.

                                          type GetResponse

                                          type GetResponse interface {
                                          	Response
                                          
                                          	// This returns the key for the requested value.
                                          	Key() string
                                          
                                          	// This returns the retreived entry.  The value may be nil.
                                          	Value() []byte
                                          
                                          	// This returns the entry's flags value.  The value is only valid when
                                          	// the entry is found.
                                          	Flags() uint32
                                          
                                          	// This returns the data version id (aka CAS) for the item.  The value is
                                          	// only valid when the entry is found.
                                          	DataVersionId() uint64
                                          }

                                            Response returned by Get/GetKey/GetAndTouch requests.

                                            func NewGetErrorResponse

                                            func NewGetErrorResponse(key string, err error) GetResponse

                                              This creates a GetResponse from an error.

                                              func NewGetResponse

                                              func NewGetResponse(
                                              	key string,
                                              	status ResponseStatus,
                                              	flags uint32,
                                              	value []byte,
                                              	version uint64) GetResponse

                                                This creates a normal GetResponse.

                                                type Item

                                                type Item struct {
                                                	// The item's key (the key can be up to 250 bytes maximum).
                                                	Key string
                                                
                                                	// The item's value.
                                                	Value []byte
                                                
                                                	// Flags are server-opaque flags whose semantics are entirely up to the app.
                                                	Flags uint32
                                                
                                                	// aka CAS (check and set) in memcache documentation.
                                                	DataVersionId uint64
                                                
                                                	// 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 uint32
                                                }

                                                  An item to be gotten from or stored in a memcache server.

                                                  type MemcachedState

                                                  type MemcachedState int

                                                  type MockClient

                                                  type MockClient struct {
                                                  	// contains filtered or unexported fields
                                                  }

                                                  func (*MockClient) Add

                                                  func (c *MockClient) Add(item *Item) MutateResponse

                                                    This adds a single entry into memcache. Note: Add will fail if the item already exist in memcache.

                                                    func (*MockClient) AddMulti

                                                    func (c *MockClient) AddMulti(items []*Item) []MutateResponse

                                                      Batch version of the Add method. Note that the response entries ordering is undefined (i.e., may not match the input ordering).

                                                      func (*MockClient) Append

                                                      func (c *MockClient) Append(key string, value []byte) MutateResponse

                                                        This appends the value bytes to the end of an existing entry. Note that this does not allow you to extend past the item limit.

                                                        func (*MockClient) CasMulti

                                                        func (c *MockClient) CasMulti(items []*Item) []MutateResponse

                                                        func (*MockClient) CasSentinels

                                                        func (c *MockClient) CasSentinels(items []*Item) []MutateResponse

                                                        func (*MockClient) Decrement

                                                        func (c *MockClient) Decrement(
                                                        	key string,
                                                        	delta uint64,
                                                        	initValue uint64,
                                                        	expiration uint32) CountResponse

                                                          This decrements the key's counter by delta. If the counter does not exist, one of two things may happen: 1. If the expiration value is all one-bits (0xffffffff), the operation will fail with StatusNotFound. 2. For all other expiration values, the operation will succeed by seeding the value for this key with the provided initValue to expire with the provided expiration time. The flags will be set to zero.

                                                          NOTE: 1. If you want to set the value of the counter with add/set/replace, the objects data must be the ascii representation of the value and not the byte values of a 64 bit integer. 2. Decrementing a counter will never result in a "negative value" (or cause the counter to "wrap"). instead the counter is set to 0.

                                                          func (*MockClient) Delete

                                                          func (c *MockClient) Delete(key string) MutateResponse

                                                            This deletes a single entry from memcache.

                                                            func (*MockClient) DeleteMulti

                                                            func (c *MockClient) DeleteMulti(keys []string) []MutateResponse

                                                              Batch version of the Delete method. Note that the response entries ordering is undefined (i.e., may not match the input ordering)

                                                              func (*MockClient) Flush

                                                              func (c *MockClient) Flush(expiration uint32) Response

                                                                This invalidates all existing cache items after expiration number of seconds.

                                                                func (*MockClient) Get

                                                                func (c *MockClient) Get(key string) GetResponse

                                                                  This retrieves a single entry from memcache.

                                                                  func (*MockClient) GetMulti

                                                                  func (c *MockClient) GetMulti(keys []string) map[string]GetResponse

                                                                    Batch version of the Get method.

                                                                    func (*MockClient) GetSentinels

                                                                    func (c *MockClient) GetSentinels(keys []string) map[string]GetResponse

                                                                    func (*MockClient) Increment

                                                                    func (c *MockClient) Increment(
                                                                    	key string,
                                                                    	delta uint64,
                                                                    	initValue uint64,
                                                                    	expiration uint32) CountResponse

                                                                      This increments the key's counter by delta. If the counter does not exist, one of two things may happen: 1. If the expiration value is all one-bits (0xffffffff), the operation will fail with StatusNotFound. 2. For all other expiration values, the operation will succeed by seeding the value for this key with the provided initValue to expire with the provided expiration time. The flags will be set to zero.

                                                                      NOTE: 1. If you want to set the value of the counter with add/set/replace, the objects data must be the ascii representation of the value and not the byte values of a 64 bit integer. 2. Incrementing the counter may cause the counter to wrap.

                                                                      func (*MockClient) Prepend

                                                                      func (c *MockClient) Prepend(key string, value []byte) MutateResponse

                                                                        This prepends the value bytes to the end of an existing entry. Note that this does not allow you to extend past the item limit.

                                                                        func (*MockClient) Replace

                                                                        func (c *MockClient) Replace(item *Item) MutateResponse

                                                                          This replaces a single entry in memcache. Note: Replace will fail if the does not exist in memcache.

                                                                          func (*MockClient) Set

                                                                          func (c *MockClient) Set(item *Item) MutateResponse

                                                                            This sets a single entry into memcache. If the item's data version id (aka CAS) is nonzero, the set operation can only succeed if the item exists in memcache and has a same data version id.

                                                                            func (*MockClient) SetMulti

                                                                            func (c *MockClient) SetMulti(items []*Item) []MutateResponse

                                                                              Batch version of the Set method. Note that the response entries ordering is undefined (i.e., may not match the input ordering).

                                                                              func (*MockClient) SetSentinels

                                                                              func (c *MockClient) SetSentinels(items []*Item) []MutateResponse

                                                                              func (*MockClient) Stat

                                                                              func (c *MockClient) Stat(statsKey string) StatResponse

                                                                                This requests the server statistics. When the key is an empty string, the server will respond with a "default" set of statistics information.

                                                                                func (*MockClient) Verbosity

                                                                                func (c *MockClient) Verbosity(verbosity uint32) Response

                                                                                  This set the verbosity level of the server.

                                                                                  func (*MockClient) Version

                                                                                  func (c *MockClient) Version() VersionResponse

                                                                                    This returns the server's version string.

                                                                                    type MutateResponse

                                                                                    type MutateResponse interface {
                                                                                    	Response
                                                                                    
                                                                                    	// This returns the input key (useful for SetMulti where operations may be
                                                                                    	// applied out of order).
                                                                                    	Key() string
                                                                                    
                                                                                    	// This returns the data version id (aka CAS) for the item.  For delete
                                                                                    	// requests, this always returns zero.
                                                                                    	DataVersionId() uint64
                                                                                    }

                                                                                      Response returned by Set/Add/Replace/Delete/Append/Prepend requests.

                                                                                      func NewMutateErrorResponse

                                                                                      func NewMutateErrorResponse(key string, err error) MutateResponse

                                                                                        This creates a MutateResponse from an error.

                                                                                        func NewMutateResponse

                                                                                        func NewMutateResponse(
                                                                                        	key string,
                                                                                        	status ResponseStatus,
                                                                                        	version uint64) MutateResponse

                                                                                          This creates a normal MutateResponse.

                                                                                          type Operation

                                                                                          type Operation int
                                                                                          const (
                                                                                          	Increment Operation = iota
                                                                                          	Decrement
                                                                                          )

                                                                                          type RawAsciiClient

                                                                                          type RawAsciiClient struct {
                                                                                          	// contains filtered or unexported fields
                                                                                          }

                                                                                            An unsharded memcache client implementation which operates on a pre-existing io channel (The user must explicitly setup and close down the channel), using the ascii memcache protocol. Note that the client assumes nothing else is sending or receiving on the network channel. In general, all client operations are serialized (Use multiple channels / clients if parallelism is needed).

                                                                                            Example
                                                                                            Output:
                                                                                            
                                                                                            

                                                                                            func (*RawAsciiClient) Add

                                                                                            func (c *RawAsciiClient) Add(item *Item) MutateResponse

                                                                                            func (*RawAsciiClient) AddMulti

                                                                                            func (c *RawAsciiClient) AddMulti(items []*Item) []MutateResponse

                                                                                            func (*RawAsciiClient) Append

                                                                                            func (c *RawAsciiClient) Append(key string, value []byte) MutateResponse

                                                                                            func (*RawAsciiClient) CasMulti

                                                                                            func (c *RawAsciiClient) CasMulti(items []*Item) []MutateResponse

                                                                                            func (*RawAsciiClient) CasSentinels

                                                                                            func (c *RawAsciiClient) CasSentinels(items []*Item) []MutateResponse

                                                                                            func (*RawAsciiClient) Decrement

                                                                                            func (c *RawAsciiClient) Decrement(
                                                                                            	key string,
                                                                                            	delta uint64,
                                                                                            	initValue uint64,
                                                                                            	expiration uint32) CountResponse

                                                                                            func (*RawAsciiClient) Delete

                                                                                            func (c *RawAsciiClient) Delete(key string) MutateResponse

                                                                                            func (*RawAsciiClient) DeleteMulti

                                                                                            func (c *RawAsciiClient) DeleteMulti(keys []string) []MutateResponse

                                                                                            func (*RawAsciiClient) Flush

                                                                                            func (c *RawAsciiClient) Flush(expiration uint32) Response

                                                                                            func (*RawAsciiClient) Get

                                                                                            func (c *RawAsciiClient) Get(key string) GetResponse

                                                                                            func (*RawAsciiClient) GetMulti

                                                                                            func (c *RawAsciiClient) GetMulti(keys []string) map[string]GetResponse

                                                                                            func (*RawAsciiClient) GetSentinels

                                                                                            func (c *RawAsciiClient) GetSentinels(keys []string) map[string]GetResponse

                                                                                            func (*RawAsciiClient) Increment

                                                                                            func (c *RawAsciiClient) Increment(
                                                                                            	key string,
                                                                                            	delta uint64,
                                                                                            	initValue uint64,
                                                                                            	expiration uint32) CountResponse

                                                                                            func (*RawAsciiClient) IsValidState

                                                                                            func (c *RawAsciiClient) IsValidState() bool

                                                                                            func (*RawAsciiClient) Prepend

                                                                                            func (c *RawAsciiClient) Prepend(key string, value []byte) MutateResponse

                                                                                            func (*RawAsciiClient) Replace

                                                                                            func (c *RawAsciiClient) Replace(item *Item) MutateResponse

                                                                                            func (*RawAsciiClient) Set

                                                                                            func (c *RawAsciiClient) Set(item *Item) MutateResponse

                                                                                            func (*RawAsciiClient) SetMulti

                                                                                            func (c *RawAsciiClient) SetMulti(items []*Item) []MutateResponse

                                                                                            func (*RawAsciiClient) SetSentinels

                                                                                            func (c *RawAsciiClient) SetSentinels(items []*Item) []MutateResponse

                                                                                            func (*RawAsciiClient) ShardId

                                                                                            func (c *RawAsciiClient) ShardId() int

                                                                                            func (*RawAsciiClient) Stat

                                                                                            func (c *RawAsciiClient) Stat(statsKey string) StatResponse

                                                                                            func (*RawAsciiClient) Verbosity

                                                                                            func (c *RawAsciiClient) Verbosity(verbosity uint32) Response

                                                                                            func (*RawAsciiClient) Version

                                                                                            func (c *RawAsciiClient) Version() VersionResponse

                                                                                            type RawBinaryClient

                                                                                            type RawBinaryClient struct {
                                                                                            	// contains filtered or unexported fields
                                                                                            }

                                                                                              An unsharded memcache client implementation which operates on a pre-existing io channel (The user must explicitly setup and close down the channel), using the binary memcached protocol. Note that the client assumes nothing else is sending or receiving on the network channel. In general, all client operations are serialized (Use multiple channels / clients if parallelism is needed).

                                                                                              Example
                                                                                              Output:
                                                                                              
                                                                                              

                                                                                              func (*RawBinaryClient) Add

                                                                                              func (c *RawBinaryClient) Add(item *Item) MutateResponse

                                                                                                See Client interface for documentation.

                                                                                                func (*RawBinaryClient) AddMulti

                                                                                                func (c *RawBinaryClient) AddMulti(items []*Item) []MutateResponse

                                                                                                  See Client interface for documentation.

                                                                                                  func (*RawBinaryClient) Append

                                                                                                  func (c *RawBinaryClient) Append(key string, value []byte) MutateResponse

                                                                                                    See Client interface for documentation.

                                                                                                    func (*RawBinaryClient) CasMulti

                                                                                                    func (c *RawBinaryClient) CasMulti(items []*Item) []MutateResponse

                                                                                                      See Client interface for documentation.

                                                                                                      func (*RawBinaryClient) CasSentinels

                                                                                                      func (c *RawBinaryClient) CasSentinels(items []*Item) []MutateResponse

                                                                                                        See Client interface for documentation.

                                                                                                        func (*RawBinaryClient) Decrement

                                                                                                        func (c *RawBinaryClient) Decrement(
                                                                                                        	key string,
                                                                                                        	delta uint64,
                                                                                                        	initValue uint64,
                                                                                                        	expiration uint32) CountResponse

                                                                                                          See Client interface for documentation.

                                                                                                          func (*RawBinaryClient) Delete

                                                                                                          func (c *RawBinaryClient) Delete(key string) MutateResponse

                                                                                                            See Client interface for documentation.

                                                                                                            func (*RawBinaryClient) DeleteMulti

                                                                                                            func (c *RawBinaryClient) DeleteMulti(keys []string) []MutateResponse

                                                                                                              See Client interface for documentation.

                                                                                                              func (*RawBinaryClient) Flush

                                                                                                              func (c *RawBinaryClient) Flush(expiration uint32) Response

                                                                                                                See Client interface for documentation.

                                                                                                                func (*RawBinaryClient) Get

                                                                                                                func (c *RawBinaryClient) Get(key string) GetResponse

                                                                                                                  See Client interface for documentation.

                                                                                                                  func (*RawBinaryClient) GetMulti

                                                                                                                  func (c *RawBinaryClient) GetMulti(keys []string) map[string]GetResponse

                                                                                                                    See Client interface for documentation.

                                                                                                                    func (*RawBinaryClient) GetSentinels

                                                                                                                    func (c *RawBinaryClient) GetSentinels(keys []string) map[string]GetResponse

                                                                                                                    func (*RawBinaryClient) Increment

                                                                                                                    func (c *RawBinaryClient) Increment(
                                                                                                                    	key string,
                                                                                                                    	delta uint64,
                                                                                                                    	initValue uint64,
                                                                                                                    	expiration uint32) CountResponse

                                                                                                                      See Client interface for documentation.

                                                                                                                      func (*RawBinaryClient) IsValidState

                                                                                                                      func (c *RawBinaryClient) IsValidState() bool

                                                                                                                        See ClientShard interface for documentation.

                                                                                                                        func (*RawBinaryClient) Prepend

                                                                                                                        func (c *RawBinaryClient) Prepend(key string, value []byte) MutateResponse

                                                                                                                          See Client interface for documentation.

                                                                                                                          func (*RawBinaryClient) Replace

                                                                                                                          func (c *RawBinaryClient) Replace(item *Item) MutateResponse

                                                                                                                            See Client interface for documentation.

                                                                                                                            func (*RawBinaryClient) Set

                                                                                                                            func (c *RawBinaryClient) Set(item *Item) MutateResponse

                                                                                                                              See Client interface for documentation.

                                                                                                                              func (*RawBinaryClient) SetMulti

                                                                                                                              func (c *RawBinaryClient) SetMulti(items []*Item) []MutateResponse

                                                                                                                                See Client interface for documentation.

                                                                                                                                func (*RawBinaryClient) SetSentinels

                                                                                                                                func (c *RawBinaryClient) SetSentinels(items []*Item) []MutateResponse

                                                                                                                                  See Client interface for documentation.

                                                                                                                                  func (*RawBinaryClient) ShardId

                                                                                                                                  func (c *RawBinaryClient) ShardId() int

                                                                                                                                    See ClientShard interface for documentation.

                                                                                                                                    func (*RawBinaryClient) Stat

                                                                                                                                    func (c *RawBinaryClient) Stat(statsKey string) StatResponse

                                                                                                                                      See Client interface for documentation.

                                                                                                                                      func (*RawBinaryClient) Verbosity

                                                                                                                                      func (c *RawBinaryClient) Verbosity(verbosity uint32) Response

                                                                                                                                        See Client interface for documentation.

                                                                                                                                        func (*RawBinaryClient) Version

                                                                                                                                        func (c *RawBinaryClient) Version() VersionResponse

                                                                                                                                          See Client interface for documentation.

                                                                                                                                          type Response

                                                                                                                                          type Response interface {
                                                                                                                                          	// This returns the status returned by the memcache server.  When Error()
                                                                                                                                          	// is non-nil, this value may not be valid.
                                                                                                                                          	//
                                                                                                                                          	// NOTE:
                                                                                                                                          	// 1. For stat request, this returns the first non-StatusNoError encountered
                                                                                                                                          	//    (or StatusNoError if there were no errors).
                                                                                                                                          	// 2. If the client is sharded, flush/stats/version/verbosity requests
                                                                                                                                          	//    will return the first non-StatusNoError encountered (or StatusNoError
                                                                                                                                          	//    if there were no errors).
                                                                                                                                          	Status() ResponseStatus
                                                                                                                                          
                                                                                                                                          	// This returns nil when no error is encountered by the client, and the
                                                                                                                                          	// response status returned by the memcache server is StatusNoError.
                                                                                                                                          	// Otherwise, this returns an error.
                                                                                                                                          	//
                                                                                                                                          	// NOTE:
                                                                                                                                          	// 1. For get requests, this also returns nil when the response status
                                                                                                                                          	//    StatusKeyNotFound.
                                                                                                                                          	// 2. For stat request, this returns the first error encountered (or nil
                                                                                                                                          	//    if there were no errors).
                                                                                                                                          	// 3. If the client is sharded, flush/stats/version/verbosity requests
                                                                                                                                          	//    will return the first error encountered (or nil if there were no
                                                                                                                                          	//    errors).
                                                                                                                                          	Error() error
                                                                                                                                          }

                                                                                                                                            A generic response to a memcache request.

                                                                                                                                            func NewErrorResponse

                                                                                                                                            func NewErrorResponse(err error) Response

                                                                                                                                              This creates a Response from an error.

                                                                                                                                              func NewResponse

                                                                                                                                              func NewResponse(status ResponseStatus) Response

                                                                                                                                                This creates a Response from status.

                                                                                                                                                type ResponseStatus

                                                                                                                                                type ResponseStatus uint16
                                                                                                                                                const (
                                                                                                                                                	StatusNoError ResponseStatus = iota
                                                                                                                                                	StatusKeyNotFound
                                                                                                                                                	StatusKeyExists
                                                                                                                                                	StatusValueTooLarge
                                                                                                                                                	StatusInvalidArguments
                                                                                                                                                	StatusItemNotStored
                                                                                                                                                	StatusIncrDecrOnNonNumericValue
                                                                                                                                                	StatusVbucketBelongsToAnotherServer // Not used
                                                                                                                                                	StatusAuthenticationError           // Not used
                                                                                                                                                	StatusAuthenticationContinue        // Not used
                                                                                                                                                )
                                                                                                                                                const (
                                                                                                                                                	StatusUnknownCommand ResponseStatus = 0x81 + iota
                                                                                                                                                	StatusOutOfMemory
                                                                                                                                                	StatusNotSupported
                                                                                                                                                	StatusInternalError
                                                                                                                                                	StatusBusy
                                                                                                                                                	StatusTempFailure
                                                                                                                                                )

                                                                                                                                                type ShardManager

                                                                                                                                                type ShardManager interface {
                                                                                                                                                	// This returns the shard id and a connection to shard for a single key.
                                                                                                                                                	// If the key does not belong to any shard, this returns (-1, nil). Note
                                                                                                                                                	// that the connection may be nil for valid shard id (for instance, if
                                                                                                                                                	// the shard server is temporarily unavailable).
                                                                                                                                                	GetShard(key string) (shardId int, conn net2.ManagedConn, err error)
                                                                                                                                                
                                                                                                                                                	// This returns a (shard id -> (connection, list of keys)) mapping for
                                                                                                                                                	// the requested keys.  Keys that do not belong to any shard are mapped
                                                                                                                                                	// to shard id -1.
                                                                                                                                                	GetShardsForKeys(keys []string) map[int]*ShardMapping
                                                                                                                                                
                                                                                                                                                	// This returns a (shard id -> (connection, list of items)) mapping for
                                                                                                                                                	// the requested items.  Items that do not belong to any shard are mapped
                                                                                                                                                	// to shard id -1.
                                                                                                                                                	GetShardsForItems(items []*Item) map[int]*ShardMapping
                                                                                                                                                
                                                                                                                                                	// *** This method is specific to Dropbox zookeeper-managed memcache ***
                                                                                                                                                	// This returns a (shard id -> (connection, list of items)) mapping for
                                                                                                                                                	// the requested sentinel keys. Sentinel keys that do not belong to any
                                                                                                                                                	// shard are mapped to shard id -1.
                                                                                                                                                	GetShardsForSentinelsFromKeys(keys []string) map[int]*ShardMapping
                                                                                                                                                
                                                                                                                                                	// *** This method is specific to Dropbox zookeeper-managed memcache ***
                                                                                                                                                	// This returns a (shard id -> (connection, list of items)) mapping for
                                                                                                                                                	// the requested sentinel items. Sentinel items that do not belong to any
                                                                                                                                                	// shard are mapped to shard id -1.
                                                                                                                                                	GetShardsForSentinelsFromItems(items []*Item) map[int]*ShardMapping
                                                                                                                                                
                                                                                                                                                	// This return a (shard id -> connection) mapping for all shards.
                                                                                                                                                	GetAllShards() map[int]net2.ManagedConn
                                                                                                                                                }

                                                                                                                                                  The ShardManager decides which memcache shard a key/item belongs to, and provide connections to the shards.

                                                                                                                                                  func NewStaticShardManager

                                                                                                                                                  func NewStaticShardManager(
                                                                                                                                                  	serverAddrs []string,
                                                                                                                                                  	shardFunc func(key string, numShard int) (shard int),
                                                                                                                                                  	options net2.ConnectionOptions) ShardManager

                                                                                                                                                    This creates a StaticShardManager, which returns connections from a static list of memcache shards.

                                                                                                                                                    type ShardMapping

                                                                                                                                                    type ShardMapping struct {
                                                                                                                                                    	Connection net2.ManagedConn
                                                                                                                                                    	ConnErr    error
                                                                                                                                                    	Keys       []string // Populated by the 4 GetShards* methods
                                                                                                                                                    	Items      []*Item  // Populated by GetShardsForItems and GetShardsForSentinelsFromItems
                                                                                                                                                    	WarmingUp  bool     // Populated by GetShardsForSentinels
                                                                                                                                                    }

                                                                                                                                                      Used for returning shard mapping results from ShardManager's GetShardsForKeys/GetShardsForItems calls.

                                                                                                                                                      type ShardState

                                                                                                                                                      type ShardState struct {
                                                                                                                                                      	Address string
                                                                                                                                                      	State   MemcachedState
                                                                                                                                                      }

                                                                                                                                                      type ShardedClient

                                                                                                                                                      type ShardedClient struct {
                                                                                                                                                      	// contains filtered or unexported fields
                                                                                                                                                      }

                                                                                                                                                        A sharded memcache client implementation where sharding management is handled by the provided ShardManager.

                                                                                                                                                        Example
                                                                                                                                                        Output:
                                                                                                                                                        
                                                                                                                                                        

                                                                                                                                                        func (*ShardedClient) Add

                                                                                                                                                        func (c *ShardedClient) Add(item *Item) MutateResponse

                                                                                                                                                          See Client interface for documentation.

                                                                                                                                                          func (*ShardedClient) AddMulti

                                                                                                                                                          func (c *ShardedClient) AddMulti(items []*Item) []MutateResponse

                                                                                                                                                            See Client interface for documentation.

                                                                                                                                                            func (*ShardedClient) Append

                                                                                                                                                            func (c *ShardedClient) Append(key string, value []byte) MutateResponse

                                                                                                                                                              See Client interface for documentation.

                                                                                                                                                              func (*ShardedClient) CasMulti

                                                                                                                                                              func (c *ShardedClient) CasMulti(items []*Item) []MutateResponse

                                                                                                                                                                See Client interface for documentation.

                                                                                                                                                                func (*ShardedClient) CasSentinels

                                                                                                                                                                func (c *ShardedClient) CasSentinels(items []*Item) []MutateResponse

                                                                                                                                                                  See Client interface for documentation.

                                                                                                                                                                  func (*ShardedClient) Decrement

                                                                                                                                                                  func (c *ShardedClient) Decrement(
                                                                                                                                                                  	key string,
                                                                                                                                                                  	delta uint64,
                                                                                                                                                                  	initValue uint64,
                                                                                                                                                                  	expiration uint32) CountResponse

                                                                                                                                                                    See Client interface for documentation.

                                                                                                                                                                    func (*ShardedClient) Delete

                                                                                                                                                                    func (c *ShardedClient) Delete(key string) MutateResponse

                                                                                                                                                                      See Client interface for documentation.

                                                                                                                                                                      func (*ShardedClient) DeleteMulti

                                                                                                                                                                      func (c *ShardedClient) DeleteMulti(keys []string) []MutateResponse

                                                                                                                                                                        See Client interface for documentation.

                                                                                                                                                                        func (*ShardedClient) Flush

                                                                                                                                                                        func (c *ShardedClient) Flush(expiration uint32) Response

                                                                                                                                                                          See Client interface for documentation.

                                                                                                                                                                          func (*ShardedClient) Get

                                                                                                                                                                          func (c *ShardedClient) Get(key string) GetResponse

                                                                                                                                                                            See Client interface for documentation.

                                                                                                                                                                            func (*ShardedClient) GetMulti

                                                                                                                                                                            func (c *ShardedClient) GetMulti(keys []string) map[string]GetResponse

                                                                                                                                                                              See Client interface for documentation.

                                                                                                                                                                              func (*ShardedClient) GetSentinels

                                                                                                                                                                              func (c *ShardedClient) GetSentinels(keys []string) map[string]GetResponse

                                                                                                                                                                                See Client interface for documentation.

                                                                                                                                                                                func (*ShardedClient) Increment

                                                                                                                                                                                func (c *ShardedClient) Increment(
                                                                                                                                                                                	key string,
                                                                                                                                                                                	delta uint64,
                                                                                                                                                                                	initValue uint64,
                                                                                                                                                                                	expiration uint32) CountResponse

                                                                                                                                                                                  See Client interface for documentation.

                                                                                                                                                                                  func (*ShardedClient) Prepend

                                                                                                                                                                                  func (c *ShardedClient) Prepend(key string, value []byte) MutateResponse

                                                                                                                                                                                    See Client interface for documentation.

                                                                                                                                                                                    func (*ShardedClient) Replace

                                                                                                                                                                                    func (c *ShardedClient) Replace(item *Item) MutateResponse

                                                                                                                                                                                      See Client interface for documentation.

                                                                                                                                                                                      func (*ShardedClient) Set

                                                                                                                                                                                      func (c *ShardedClient) Set(item *Item) MutateResponse

                                                                                                                                                                                        See Client interface for documentation.

                                                                                                                                                                                        func (*ShardedClient) SetMulti

                                                                                                                                                                                        func (c *ShardedClient) SetMulti(items []*Item) []MutateResponse

                                                                                                                                                                                          See Client interface for documentation.

                                                                                                                                                                                          func (*ShardedClient) SetSentinels

                                                                                                                                                                                          func (c *ShardedClient) SetSentinels(items []*Item) []MutateResponse

                                                                                                                                                                                            See Client interface for documentation.

                                                                                                                                                                                            func (*ShardedClient) Stat

                                                                                                                                                                                            func (c *ShardedClient) Stat(statsKey string) StatResponse

                                                                                                                                                                                              See Client interface for documentation.

                                                                                                                                                                                              func (*ShardedClient) Verbosity

                                                                                                                                                                                              func (c *ShardedClient) Verbosity(verbosity uint32) Response

                                                                                                                                                                                                See Client interface for documentation.

                                                                                                                                                                                                func (*ShardedClient) Version

                                                                                                                                                                                                func (c *ShardedClient) Version() VersionResponse

                                                                                                                                                                                                  See Client interface for documentation.

                                                                                                                                                                                                  type StatResponse

                                                                                                                                                                                                  type StatResponse interface {
                                                                                                                                                                                                  	Response
                                                                                                                                                                                                  
                                                                                                                                                                                                  	// This returns the retrieved stat entries.  On error status, this returns
                                                                                                                                                                                                  	// nil.  The mapping is stored as:
                                                                                                                                                                                                  	//      shard id -> stats key -> stats value
                                                                                                                                                                                                  	// (If the client is unsharded, the shard id is always zero).
                                                                                                                                                                                                  	Entries() map[int](map[string]string)
                                                                                                                                                                                                  }

                                                                                                                                                                                                    Response returned by Stat request.

                                                                                                                                                                                                    func NewStatErrorResponse

                                                                                                                                                                                                    func NewStatErrorResponse(
                                                                                                                                                                                                    	err error,
                                                                                                                                                                                                    	entries map[int](map[string]string)) StatResponse

                                                                                                                                                                                                      This creates a StatResponse from an error.

                                                                                                                                                                                                      func NewStatResponse

                                                                                                                                                                                                      func NewStatResponse(
                                                                                                                                                                                                      	status ResponseStatus,
                                                                                                                                                                                                      	entries map[int](map[string]string)) StatResponse

                                                                                                                                                                                                        This creates a normal StatResponse.

                                                                                                                                                                                                        type StaticShardManager

                                                                                                                                                                                                        type StaticShardManager struct {
                                                                                                                                                                                                        	BaseShardManager
                                                                                                                                                                                                        }

                                                                                                                                                                                                          A shard manager that returns connections from a static list of memcache shards. NOTE: This is only for illustration purposes. DO NOT USE IN PRODUCTION. (Dropbox internally uses a different shard manager which is also based on BaseShardManager. Our memcache config is managed by zookeeper. When our memcache config changes, zookeeper will notify the shard manager of these updates and the shard manager will in turn swap in/out shards via UpdateShardStates.)

                                                                                                                                                                                                          type VersionResponse

                                                                                                                                                                                                          type VersionResponse interface {
                                                                                                                                                                                                          	Response
                                                                                                                                                                                                          
                                                                                                                                                                                                          	// This returns the memcache version entries.  On error status, this
                                                                                                                                                                                                          	// returns an empty string.  The mapping is stored as:
                                                                                                                                                                                                          	//      shard id -> version string
                                                                                                                                                                                                          	// (If the client is unsharded, the shard id is always zero).
                                                                                                                                                                                                          	Versions() map[int]string
                                                                                                                                                                                                          }

                                                                                                                                                                                                            Response returned by Version request.

                                                                                                                                                                                                            func NewVersionErrorResponse

                                                                                                                                                                                                            func NewVersionErrorResponse(
                                                                                                                                                                                                            	err error,
                                                                                                                                                                                                            	versions map[int]string) VersionResponse

                                                                                                                                                                                                              This creates a VersionResponse from an error.

                                                                                                                                                                                                              func NewVersionResponse

                                                                                                                                                                                                              func NewVersionResponse(
                                                                                                                                                                                                              	status ResponseStatus,
                                                                                                                                                                                                              	versions map[int]string) VersionResponse

                                                                                                                                                                                                                This creates a normal VersionResponse.