memcache

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: May 26, 2020 License: BSD-3-Clause Imports: 19 Imported by: 3

Documentation

Index

Constants

View Source
const VERSION = "0.1.0"

Variables

View Source
var (
	// ErrInvalidCmd means that the number of command parts is invalid,
	// or the type of a part if invalid.
	ErrInvalidCmd = errors.New("invalid cmd")

	// ErrNonMemcacheCmd means that the command is not defined in original memcache protocal.
	// refer: https://github.com/memcached/memcached/blob/master/doc/protocol.txt
	ErrNonMemcacheCmd = errors.New("non memcache command")

	// ErrValueTooLarge means that the value of a store command (e.g. set) is too large
	ErrValueTooLarge = errors.New("value too large")

	// ErrKeyLength means that the length of key is invalid
	ErrKeyLength = errors.New("key length error")

	// ErrBadDataChunk means that data chunk of a value is not match its size flag.
	ErrBadDataChunk = errors.New("bad data chunk")

	// ErrNetworkError means that a failure happend at reading/writing to a client connection.
	ErrNetworkError = errors.New("network error")

	ErrOOM = errors.New("memory shortage")
)

Functions

func InitTokens

func InitTokens()

func NewMapStore

func NewMapStore() *mapStore

func WriteFull

func WriteFull(w io.Writer, buf []byte) error

Types

type Item

type Item struct {
	ReceiveTime time.Time
	Flag        int
	Exptime     int
	Cas         int
	cmem.CArray `json:"-"`
}

func (*Item) String

func (it *Item) String() (s string)

type ReqHistoy

type ReqHistoy struct {
	Cmd        string
	Keys       []string
	WaitTime   time.Duration
	ServeStart time.Time
	ServeTime  time.Duration
	Stat       string
	StatStart  time.Time
	Working    bool
}

type ReqLimiter

type ReqLimiter struct {
	Chan      chan int   `json:"-"`
	Owners    []*Request `json:"-"`
	Histories []ReqHistoy

	// TODO: more!
	NumWait int32
	MaxWait time.Duration
}
var (
	SlowCmdTime = time.Millisecond * 100 // 100ms
	RL          *ReqLimiter
)

func NewReqLimiter

func NewReqLimiter(n int) *ReqLimiter

func (*ReqLimiter) Get

func (rl *ReqLimiter) Get(req *Request)

func (*ReqLimiter) Put

func (rl *ReqLimiter) Put(req *Request)

type Request

type Request struct {
	ReceiveTime time.Time
	Cmd         string   // get, set, delete, quit, etc.
	Keys        []string // keys
	Item        *Item
	NoReply     bool

	Token   int
	Working bool
}

func (*Request) Check

func (req *Request) Check(resp *Response) error

func (*Request) Clear

func (req *Request) Clear()

func (*Request) Process

func (req *Request) Process(store StorageClient, stat *Stats) (resp *Response, err error)

func (*Request) Read

func (req *Request) Read(b *bufio.Reader) error

func (*Request) SetStat

func (req *Request) SetStat(stat string)

func (*Request) String

func (req *Request) String() (s string)

func (*Request) Write

func (req *Request) Write(w io.Writer) (e error)

type Response

type Response struct {
	Status  string
	Msg     string
	Cas     bool
	Noreply bool
	Items   map[string]*Item
}

func (*Response) CleanBuffer

func (resp *Response) CleanBuffer()

func (*Response) Read

func (resp *Response) Read(b *bufio.Reader) error

func (*Response) String

func (resp *Response) String() (s string)

func (*Response) Write

func (resp *Response) Write(w io.Writer) error

type Server

type Server struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewServer

func NewServer(store Storage) *Server

func (*Server) HandleSignals

func (s *Server) HandleSignals(errorlog string, accesslog string, analysislog string)

func (*Server) Listen

func (s *Server) Listen(addr string) (e error)

func (*Server) Serve

func (s *Server) Serve() (e error)

func (*Server) Shutdown

func (s *Server) Shutdown()

type ServerConn

type ServerConn struct {
	RemoteAddr string
	// contains filtered or unexported fields
}

func (*ServerConn) Close

func (c *ServerConn) Close()

func (*ServerConn) Serve

func (c *ServerConn) Serve(storageClient StorageClient, stats *Stats) (e error)

func (*ServerConn) ServeOnce

func (c *ServerConn) ServeOnce(storageClient StorageClient, stats *Stats) (err error)

func (*ServerConn) Shutdown

func (c *ServerConn) Shutdown()

type Stats

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

func NewStats

func NewStats() *Stats

func (*Stats) Stats

func (s *Stats) Stats() map[string]int64

type Storage

type Storage interface {
	Client() StorageClient
}

type StorageClient

type StorageClient interface {
	GetSuccessedTargets() []string
	Clean()
	Get(key string) (*Item, error)
	GetMulti(keys []string) (map[string]*Item, error)
	Set(key string, item *Item, noreply bool) (bool, error)
	Append(key string, value []byte) (bool, error)
	Incr(key string, value int) (int, error)
	Delete(key string) (bool, error)
	Len() int
	Close()
	Process(key string, args []string) (string, string)
}

Jump to

Keyboard shortcuts

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