server

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StateKey int = iota
	StateFlag
	StateSize
	StateCasID
)

Variables

View Source
var (
	ErrCacheMiss = xerrors.New("cache miss hit")

	// ErrMalformedKey is returned when an invalid key is used.
	// Keys must be at maximum 250 bytes long and not
	// contain whitespace or control characters.
	ErrMalformedKey = xerrors.New("malformed: key is too long or contains invalid characters")

	ErrSetTimeout            = xerrors.New("timeout must be 1 or more")
	ErrSetMaxIdleConnections = xerrors.New("maxIdle must be 1 or more")
)
View Source
var (
	// ErrMemcacheCacheMiss means that a Get failed because the item wasn't present.
	ErrMemcacheCacheMiss = xerrors.New("memcache: cache miss")

	// ErrMemcacheCASConflict means that a CompareAndSwap call failed due to the
	// cached value being modified between the Get and the CompareAndSwap.
	// If the cached value was simply evicted rather than replaced,
	// ErrNotStored will be returned instead.
	ErrMemcacheCASConflict = xerrors.New("memcache: compare-and-swap conflict")

	// ErrMemcacheNotStored means that a conditional write operation (i.e. Add or
	// CompareAndSwap) failed because the condition was not satisfied.
	ErrMemcacheNotStored = xerrors.New("memcache: item not stored")

	// ErrMemcacheServerError means that a server error occurred.
	ErrMemcacheServerError = xerrors.New("memcache: server error")

	// ErrMemcacheNoStats means that no statistics were available.
	ErrMemcacheNoStats = xerrors.New("memcache: no statistics available")

	// ErrMemcacheNoServers is returned when no servers are configured or available.
	ErrMemcacheNoServers = xerrors.New("memcache: no servers configured or available")
)
View Source
var (
	ErrRedisCacheMiss = xerrors.New("redis: cache miss")
	ErrRedisNotStored = xerrors.New("redis: item not stored")
)
View Source
var (
	ErrCannotAssignCacheServer = xerrors.New("cannot assign cache server because server number is zero")
)

Functions

This section is empty.

Types

type CacheGetResponse

type CacheGetResponse struct {
	Value []byte
	Flags uint32
	CasID uint64
}

type CacheKey

type CacheKey interface {
	String() string
	Hash() uint32
	Addr() net.Addr
	LockKey() CacheKey
	Type() CacheKeyType
}

type CacheKeyType

type CacheKeyType int
const (
	CacheKeyTypeNone CacheKeyType = iota
	CacheKeyTypeSLC
	CacheKeyTypeLLC
)

func (CacheKeyType) MarshalJSON

func (typ CacheKeyType) MarshalJSON() ([]byte, error)

func (CacheKeyType) String

func (typ CacheKeyType) String() string

func (*CacheKeyType) UnmarshalJSON

func (typ *CacheKeyType) UnmarshalJSON(bytes []byte) error

type CacheServer

type CacheServer interface {
	GetClient() *Client
	Get(CacheKey) (*CacheGetResponse, error)
	GetMulti([]CacheKey) (*Iterator, error)
	Set(*CacheStoreRequest) error
	Add(CacheKey, []byte, time.Duration) error
	Delete(CacheKey) error
	Flush() error
	SetTimeout(time.Duration) error
	SetMaxIdleConnections(int) error
}

func NewMemcachedBySelectors

func NewMemcachedBySelectors(slcSelector *Selector, llcSelector *Selector) CacheServer

New returns a memcache client using the provided server(s) with equal weight. If a server is listed multiple times, it gets a proportional amount of weight.

func NewRedisBySelectors

func NewRedisBySelectors(slcSelector *Selector, llcSelector *Selector) CacheServer

type CacheStoreRequest

type CacheStoreRequest struct {
	Key        CacheKey
	Value      []byte
	CasID      uint64
	Expiration time.Duration
}

type Client

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

Client is a memcache client. It is safe for unlocked use by multiple concurrent goroutines.

func (*Client) AddLastLevelCacheServers

func (c *Client) AddLastLevelCacheServers(servers ...string) error

func (*Client) AddSecondLevelCacheServers

func (c *Client) AddSecondLevelCacheServers(servers ...string) error

func (*Client) RemoveLastLevelCacheServers

func (c *Client) RemoveLastLevelCacheServers(servers ...string) error

func (*Client) RemoveSecondLevelCacheServers

func (c *Client) RemoveSecondLevelCacheServers(servers ...string) error

type ConnectTimeoutError

type ConnectTimeoutError struct {
	Addr net.Addr
}

ConnectTimeoutError is the error type used when it takes too long to connect to the desired host. This level of detail can generally be ignored.

func (*ConnectTimeoutError) Error

func (cte *ConnectTimeoutError) Error() string

type HashKey

type HashKey uint32

type HashKeyOrder

type HashKeyOrder []HashKey

func (HashKeyOrder) Len

func (h HashKeyOrder) Len() int

func (HashKeyOrder) Less

func (h HashKeyOrder) Less(i, j int) bool

func (HashKeyOrder) Swap

func (h HashKeyOrder) Swap(i, j int)

type Hashring

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

func NewHashring

func NewHashring(addrs []net.Addr) *Hashring

func (*Hashring) Add

func (h *Hashring) Add(node net.Addr) *Hashring

func (*Hashring) Get

func (h *Hashring) Get(key CacheKey) net.Addr

func (*Hashring) Remove

func (h *Hashring) Remove(node net.Addr) (*Hashring, error)

type Item

type Item struct {
	// Key is the Item's key (250 bytes maximum).
	Key CacheKey

	// Value is the Item's value.
	Value []byte

	// Flags are server-opaque flags whose semantics are entirely
	// up to the app.
	Flags uint32

	// Expiration is the cache expiration time, in seconds: either a relative
	// time from now (up to 1 month), or an absolute Unix epoch time.
	// Zero means the Item has no expiration time.
	Expiration int32
	// contains filtered or unexported fields
}

Item is an item to be got or stored in a memcached server.

type Iterator

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

func NewIterator

func NewIterator(keys []CacheKey) *Iterator

func (*Iterator) Content

func (i *Iterator) Content() *CacheGetResponse

func (*Iterator) Error

func (i *Iterator) Error() error

func (*Iterator) Key

func (i *Iterator) Key() CacheKey

func (*Iterator) Next

func (i *Iterator) Next() bool

func (*Iterator) SetContent

func (i *Iterator) SetContent(idx int, res *CacheGetResponse)

func (*Iterator) SetError

func (i *Iterator) SetError(idx int, err error)

type MemcachedClient

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

func (*MemcachedClient) Add

func (c *MemcachedClient) Add(key CacheKey, value []byte, expiration time.Duration) error

func (*MemcachedClient) CompareAndSwap

func (c *MemcachedClient) CompareAndSwap(item *Item) error

CompareAndSwap writes the given item that was previously returned by Get, if the value was neither modified or evicted between the Get and the CompareAndSwap calls. The item's Key should not change between calls but all other item fields may differ. ErrCASConflict is returned if the value was modified in between the calls. ErrNotStored is returned if the value was evicted in between the calls.

func (*MemcachedClient) Decrement

func (c *MemcachedClient) Decrement(key CacheKey, delta uint64) (newValue uint64, err error)

Decrement atomically decrements key by delta. The return value is the new value after being decremented or an error. If the value didn't exist in memcached the error is ErrCacheMiss. The value in memcached must be an decimal number, or an error will be returned. On underflow, the new value is capped at zero and does not wrap around.

func (*MemcachedClient) Delete

func (c *MemcachedClient) Delete(key CacheKey) error

func (*MemcachedClient) DeleteAll

func (c *MemcachedClient) DeleteAll() error

DeleteAll deletes all items in the cache.

func (*MemcachedClient) Flush

func (c *MemcachedClient) Flush() error

func (*MemcachedClient) FlushAll

func (c *MemcachedClient) FlushAll() error

func (*MemcachedClient) Get

func (*MemcachedClient) GetClient

func (c *MemcachedClient) GetClient() *Client

func (*MemcachedClient) GetMulti

func (c *MemcachedClient) GetMulti(keys []CacheKey) (*Iterator, error)

func (*MemcachedClient) Increment

func (c *MemcachedClient) Increment(key CacheKey, delta uint64) (newValue uint64, err error)

Increment atomically increments key by delta. The return value is the new value after being incremented or an error. If the value didn't exist in memcached the error is ErrCacheMiss. The value in memcached must be an decimal number, or an error will be returned. On 64-bit overflow, the new value wraps around.

func (*MemcachedClient) Replace

func (c *MemcachedClient) Replace(item *Item) error

Replace writes the given item, but only if the server *does* already hold data for this key

func (*MemcachedClient) Set

func (*MemcachedClient) SetMaxIdleConnections

func (c *MemcachedClient) SetMaxIdleConnections(maxIdle int) error

func (*MemcachedClient) SetTimeout

func (c *MemcachedClient) SetTimeout(timeout time.Duration) error

func (*MemcachedClient) Touch

func (c *MemcachedClient) Touch(key CacheKey, seconds int32) (err error)

Touch updates the expiry for the given key. The seconds parameter is either a Unix timestamp or, if seconds is less than 1 month, the number of seconds into the future at which time the item will expire. Zero means the item has no expiration time. ErrCacheMiss is returned if the key is not in the cache. The key must be at most 250 bytes in length.

type RedisClient

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

func (*RedisClient) Add

func (c *RedisClient) Add(key CacheKey, value []byte, expiration time.Duration) error

func (*RedisClient) Delete

func (c *RedisClient) Delete(key CacheKey) error

func (*RedisClient) Flush

func (c *RedisClient) Flush() error

func (*RedisClient) Get

func (c *RedisClient) Get(key CacheKey) (*CacheGetResponse, error)

func (*RedisClient) GetClient

func (c *RedisClient) GetClient() *Client

func (*RedisClient) GetMulti

func (c *RedisClient) GetMulti(keys []CacheKey) (*Iterator, error)

func (*RedisClient) Set

func (c *RedisClient) Set(req *CacheStoreRequest) error

func (*RedisClient) SetMaxIdleConnections

func (c *RedisClient) SetMaxIdleConnections(maxIdle int) error

func (*RedisClient) SetTimeout

func (c *RedisClient) SetTimeout(timeout time.Duration) error

type Selector

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

func NewSelector

func NewSelector(servers ...string) (*Selector, error)

func (*Selector) Each

func (s *Selector) Each(f func(net.Addr) error) error

func (*Selector) PickServer

func (s *Selector) PickServer(key CacheKey) (net.Addr, error)

type StringCacheKey

type StringCacheKey string

func (StringCacheKey) Addr

func (s StringCacheKey) Addr() net.Addr

func (StringCacheKey) Hash

func (s StringCacheKey) Hash() uint32

func (StringCacheKey) LockKey

func (s StringCacheKey) LockKey() CacheKey

func (StringCacheKey) String

func (s StringCacheKey) String() string

func (StringCacheKey) Type

func (s StringCacheKey) Type() CacheKeyType

Jump to

Keyboard shortcuts

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