memcached

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: May 25, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package memcached provides an interface for building your own memcached ascii protocol servers.

Index

Constants

View Source
const (
	UserTime usageType = iota
	SystemTime
)
View Source
const (
	StatusEnd         = "END\r\n"
	StatusError       = "ERROR\r\n"
	StatusServerError = "SERVER_ERROR\r\n"
	StatusClientError = "CLIENT_ERROR %s\r\n"
	StatusStored      = "STORED\r\n"
	StatusNotStored   = "NOT_STORED\r\n"
	StatusExists      = "EXISTS\r\n"
	StatusNotFound    = "NOT_FOUND\r\n"
	StatusDeleted     = "DELETED\r\n"
	StatusTouched     = "TOUCHED\r\n"
	StatusOK          = "OK\r\n"
	StatusVersion     = "VERSION %s\r\n"
	StatusValue       = "VALUE %s %d %d\r\n"
	StatusStat        = "STAT %s %s\r\n"
)
View Source
const MAX_EXPTIME = 60 * 60 * 24 * 30 // 30 days

MAX_EXPTIME is the maximum time to send from a client before the timestamp is considered an absolute unix timestamp.

View Source
const VERSION = "0.0.0"

Variables

View Source
var (
	// ClientError is an error caused by an invalid command from the client.
	ClientError = errors.New(StatusClientError)
	// NotFound is returned when the key was not found.
	NotFound = errors.New(StatusNotFound)
	// ServerError is an error occurred servicing this request.
	ServerError = errors.New(StatusServerError)
	// Error is a generic error.
	Error = errors.New(StatusError)
)

Functions

This section is empty.

Types

type BulkResponse

type BulkResponse struct {
	Responses []MemcachedResponse
}

func (*BulkResponse) WriteResponse

func (r *BulkResponse) WriteResponse(writer io.Writer)

type ClientErrorResponse

type ClientErrorResponse struct {
	Reason string
}

func (*ClientErrorResponse) WriteResponse

func (r *ClientErrorResponse) WriteResponse(writer io.Writer)

type CounterStat

type CounterStat struct {
	Count int
	// contains filtered or unexported fields
}

func NewCounterStat

func NewCounterStat() *CounterStat

func (*CounterStat) Decrement

func (c *CounterStat) Decrement(num int)

func (*CounterStat) Increment

func (c *CounterStat) Increment(num int)

func (*CounterStat) SetCount

func (c *CounterStat) SetCount(num int)

func (*CounterStat) String

func (c *CounterStat) String() string

type Deleter

type Deleter interface {
	RequestHandler
	Delete(string) MemcachedResponse
}

A Deleter is an object who responds to a simple "delete" command.

type FuncStat

type FuncStat struct {
	Callable func() string
}

func (*FuncStat) String

func (f *FuncStat) String() string

type Getter

type Getter interface {
	RequestHandler
	Get(string) MemcachedResponse
}

A Getter is an object who responds to a simple "get" command.

type Item

type Item struct {
	Key        string
	Value      []byte
	Flags, Ttl int
	Expires    time.Time
}

func NewItem

func NewItem() *Item

NewItem initializes a new Item.

func (*Item) IsExpired

func (i *Item) IsExpired() bool

IsExpired checks if an Item is expired based on it's Ttl. If an item has no Ttl set, it is considered to never be expired.

func (*Item) SetExpires

func (i *Item) SetExpires(exptime int64)

SetExpires sets the Ttl and Expires based on the exptime send from a client. This follows standard memcached rules, and an exptime greater than 30 days is treated as an absolute unix timestamp.

func (*Item) String

func (i *Item) String() string

type ItemResponse

type ItemResponse struct {
	Item *Item
}

func (*ItemResponse) WriteResponse

func (r *ItemResponse) WriteResponse(writer io.Writer)

type MemcachedResponse

type MemcachedResponse interface {
	WriteResponse(io.Writer)
}

type RequestHandler

type RequestHandler interface{}

type Server

type Server struct {
	Addr    string
	Getter  Getter
	Setter  Setter
	Deleter Deleter
	Stats   Stats
}

func NewServer

func NewServer(listen string, handler RequestHandler) *Server

NewServer initialize a new memcached Server.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe starts listening and accepting requests to this server.

func (*Server) Serve

func (s *Server) Serve(l net.Listener) error

type Setter

type Setter interface {
	RequestHandler
	Set(*Item) MemcachedResponse
}

A Setter is an object who response to a simple "set" command.

type StaticStat

type StaticStat struct {
	Value string
}

func (*StaticStat) String

func (s *StaticStat) String() string

type Stats

type Stats struct {
	PID              *StaticStat
	Uptime           *TimerStat
	Time             *FuncStat
	Version          *StaticStat
	Golang           *StaticStat
	Goroutines       *FuncStat
	RUsageUser       *FuncStat
	RUsageSystem     *FuncStat
	CMDGet           *CounterStat
	CMDSet           *CounterStat
	GetHits          *CounterStat
	GetMisses        *CounterStat
	CurrConnections  *CounterStat
	TotalConnections *CounterStat
	Evictions        *CounterStat
}

func NewStats

func NewStats() Stats

func (Stats) Snapshot added in v0.1.4

func (s Stats) Snapshot() map[string]string

type StorageCmd

type StorageCmd struct {
	Key     string
	Flags   int
	Exptime int64
	Length  int
	Noreply bool
}

type TimerStat

type TimerStat struct {
	Start int64
}

func NewTimerStat

func NewTimerStat() *TimerStat

func (*TimerStat) String

func (t *TimerStat) String() string

Jump to

Keyboard shortcuts

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