memcache

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2023 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxKeyLength  = 200
	MaxBodyLength = 1024 * 1024 * 50
)
View Source
const FNV1A_INIT uint32 = 0x811c9dc5
View Source
const FNV1A_PRIME uint32 = 0x01000193
View Source
const VERSION = "0.1.0"
View Source
const VIRTUAL_NODES = 100

Variables

View Source
var ConnectTimeout time.Duration = time.Millisecond * 300
View Source
var MaxFreeConns = 20
View Source
var ReadTimeout time.Duration = time.Millisecond * 2000
View Source
var WriteTimeout time.Duration = time.Millisecond * 2000

Functions

func NewMapStore

func NewMapStore() *mapStore

func WriteFull

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

Types

type AutoScheduler

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

route requests by auto discoved infomation, used in beansdb

func NewAutoScheduler

func NewAutoScheduler(config []string, bs int) *AutoScheduler

func (*AutoScheduler) DivideKeysByBucket

func (c *AutoScheduler) DivideKeysByBucket(keys []string) [][]string

func (*AutoScheduler) Feedback

func (c *AutoScheduler) Feedback(host *Host, key string, adjust float64)

func (*AutoScheduler) GetHostsByKey

func (c *AutoScheduler) GetHostsByKey(key string) []*Host

func (*AutoScheduler) Stats

func (c *AutoScheduler) Stats() map[string][]float64

type Client

type Client struct {
	N, W, R int
	// contains filtered or unexported fields
}

Client of memcached

func NewClient

func NewClient(sch Scheduler, N, W, R int) (c *Client)

func (*Client) Append

func (c *Client) Append(key string, value []byte) (ok bool, targets []string, final_err error)

func (*Client) Delete

func (c *Client) Delete(key string) (r bool, targets []string, err error)

func (*Client) Get

func (c *Client) Get(key string) (r *Item, targets []string, err error)

func (*Client) GetMulti

func (c *Client) GetMulti(keys []string) (rs map[string]*Item, targets []string, err error)

func (*Client) Incr

func (c *Client) Incr(key string, value int) (result int, targets []string, err error)

func (*Client) Len

func (c *Client) Len() int

func (*Client) Set

func (c *Client) Set(key string, item *Item, noreply bool) (ok bool, targets []string, final_err error)

type ConsistantHashScheduler

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

ConsistantHashScheduler route requests by consistant hash

func (*ConsistantHashScheduler) DivideKeysByBucket

func (c *ConsistantHashScheduler) DivideKeysByBucket(keys []string) [][]string

func (ConsistantHashScheduler) Feedback

func (c ConsistantHashScheduler) Feedback(host *Host, key string, adjust float64)

func (*ConsistantHashScheduler) GetHostsByKey

func (c *ConsistantHashScheduler) GetHostsByKey(key string) []*Host

func (ConsistantHashScheduler) Stats

func (c ConsistantHashScheduler) Stats() map[string][]float64

type DistributeStorage

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

type Feedback

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

type HashMethod

type HashMethod func(v []byte) (h uint32)

type Host

type Host struct {
	Addr string
	// contains filtered or unexported fields
}

func NewHost

func NewHost(addr string) *Host

func (*Host) Append

func (host *Host) Append(key string, value []byte) (bool, error)

func (*Host) Close

func (host *Host) Close()

func (*Host) Delete

func (host *Host) Delete(key string) (bool, error)

func (*Host) Get

func (host *Host) Get(key string) (*Item, error)

func (*Host) GetMulti

func (host *Host) GetMulti(keys []string) (map[string]*Item, error)

func (*Host) Incr

func (host *Host) Incr(key string, value int) (int, error)

func (*Host) Len

func (host *Host) Len() int

func (*Host) Set

func (host *Host) Set(key string, item *Item, noreply bool) (bool, error)

func (*Host) Stat

func (host *Host) Stat(keys []string) (map[string]string, error)

type Item

type Item struct {
	Flag    int
	Exptime int
	Cas     int
	Body    []byte
}

func (*Item) String

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

type ManualScheduler

type ManualScheduler struct {
	N int
	// contains filtered or unexported fields
}

ManualScheduler route request by configure by hand

func NewManualScheduler

func NewManualScheduler(config map[string][]string, bs, n int) *ManualScheduler

NewManualScheduler the string is a Hex int string, if it start with -, it means serve the bucket as a backup

func (*ManualScheduler) DivideKeysByBucket

func (c *ManualScheduler) DivideKeysByBucket(keys []string) [][]string

func (*ManualScheduler) Feedback

func (c *ManualScheduler) Feedback(host *Host, key string, adjust float64)

func (*ManualScheduler) GetHostsByKey

func (c *ManualScheduler) GetHostsByKey(key string) (hosts []*Host)

func (*ManualScheduler) Stats

func (c *ManualScheduler) Stats() map[string][]float64

type ModScheduler

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

ModScheduler route request by Mod of HASH

func (*ModScheduler) DivideKeysByBucket

func (c *ModScheduler) DivideKeysByBucket(keys []string) [][]string

func (ModScheduler) Feedback

func (c ModScheduler) Feedback(host *Host, key string, adjust float64)

func (*ModScheduler) GetHostsByKey

func (c *ModScheduler) GetHostsByKey(key string) []*Host

func (*ModScheduler) Stats

func (c *ModScheduler) Stats() map[string][]float64

Stats 内部状态

type RClient

type RClient struct {
	N, W, R int
	// contains filtered or unexported fields
}

func NewRClient

func NewRClient(sch Scheduler, N, W, R int) (c *RClient)

func (*RClient) Append

func (c *RClient) Append(key string, value []byte) (ok bool, targets []string, final_err error)

func (*RClient) Delete

func (c *RClient) Delete(key string) (r bool, targets []string, err error)

func (*RClient) Get

func (c *RClient) Get(key string) (r *Item, targets []string, err error)

func (*RClient) GetMulti

func (c *RClient) GetMulti(keys []string) (rs map[string]*Item, targets []string, err error)

func (*RClient) Incr

func (c *RClient) Incr(key string, value int) (result int, target []string, err error)

func (*RClient) Len

func (c *RClient) Len() int

func (*RClient) Set

func (c *RClient) Set(key string, item *Item, noreply bool) (ok bool, targets []string, final_err error)

type Request

type Request struct {
	Cmd     string   // get, set, delete, quit, etc.
	Keys    []string // keys
	Item    *Item
	NoReply 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 DistributeStorage, stat *Stats) (resp *Response, targets []string, err error)

func (*Request) Read

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

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 {
	// contains filtered or unexported fields
}

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 Scheduler

type Scheduler interface {
	Feedback(host *Host, key string, adjust float64) // feedback for auto routing
	GetHostsByKey(key string) []*Host                // route a key to hosts
	DivideKeysByBucket(keys []string) [][]string     // route some keys to group of hosts
	Stats() map[string][]float64                     // internal status
}

Scheduler : route request to nodes

func NewConsistantHashScheduler

func NewConsistantHashScheduler(hosts []string, hashname string) Scheduler

func NewModScheduler

func NewModScheduler(hosts []string, hashname string) Scheduler

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

func (*Stats) UpdateStat

func (s *Stats) UpdateStat(key string, value int64)

type StdLogger

type StdLogger interface {
	Print(v ...interface{})
	Printf(format string, v ...interface{})
	Println(v ...interface{})
}
var Logger StdLogger = log.New(ioutil.Discard, "[BeansDB-Client] ", log.LstdFlags)

type Storage

type Storage interface {
	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
}

Jump to

Keyboard shortcuts

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