memcache

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEstablishConnection = errors.New("failed to establish connection")
	ErrNoServers           = errors.New("no servers are currently connected")
	ErrNotStored           = errors.New("failed to store Value")
	ErrError               = errors.New("incorrect syntax or error while saving the Value")
	ErrClientError         = errors.New("failed to store Value while appending/prepending")
	ErrExists              = errors.New("someone else has modified the CAS Value since last fetch")
	ErrCacheMiss           = errors.New("key does not exist in the server")
)

Functions

This section is empty.

Types

type Client

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

Client is the object that is exposed to the user. It allows the user to interact with the API.

func New

func New(addresses []string, connCount int) *Client

New creates a client object. We need a list of addresses and also a number of connections we want to establish with each of the servers. These connections are later used in the connection pool.

func (*Client) Add

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

Add creates a new item in the key/value store.

func (*Client) Append

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

Append appends data to a given item.

func (*Client) Close

func (c *Client) Close() error

Close closes all the connections we established earlier to various servers.

func (*Client) CompareAndSwap

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

CompareAndSwap sets the data if it is not updated since last fetch.

func (*Client) Decr

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

Decr decrements a numerical value for a given key with a given delta.

func (*Client) Delete

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

Delete remove a key from the key/value store.

func (*Client) Get

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

Gets returns an item for a given key.

func (*Client) Gets

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

Gets returns an item for a given key with CAS value.

func (*Client) Incr

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

Incr increments a numerical value for a given key with a given delta.

func (*Client) Prepend

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

Prepend prepends data to a given item.

func (*Client) Replace

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

Replace replaces value for a given item's key.

func (*Client) Set

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

Set is used to set a value to a new key. If a value is already set, the function returns NOT_STORED.

type ConnType

type ConnType int8
const (
	TCP ConnType = iota
	UNIX
)

type Connection

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

Connection represents a single connection to a server. We want to hold the connection itself and also a ReadWriter due to optimizations.

type Item

type Item struct {
	Key        string
	Value      []byte
	Expiration time.Duration
	Flags      int32
	CAS        int64
}

Item represent a memcache item object

type ServerList

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

ServerList holds the list of all server addresses. It is concurrent-safe.

func (*ServerList) InitializeConnectionPool

func (sl *ServerList) InitializeConnectionPool(connCount int) (map[string][]*Connection, error)

InitializeConnectionPool creates connections for server addresses.

Jump to

Keyboard shortcuts

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