geek

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DestroyGroup

func DestroyGroup(name string)

Types

type ByteView

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

ByteView 只读的字节视图,用于缓存数据

func (ByteView) ByteSLice

func (b ByteView) ByteSLice() []byte

func (ByteView) Len

func (b ByteView) Len() int

func (ByteView) String

func (b ByteView) String() string

type Client

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

func NewClient

func NewClient(addr, serviceName string) *Client

NewClient creates a new client

func (*Client) Get

func (c *Client) Get(group, key string) ([]byte, error)

Get send the url for getting specific group and key, and return the result

type ClientPicker added in v0.2.0

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

func NewClientPicker added in v0.2.0

func NewClientPicker(self string, opts ...PickerOptions) *ClientPicker

func (*ClientPicker) Log added in v0.2.0

func (s *ClientPicker) Log(format string, path ...interface{})

Log info

func (*ClientPicker) PickPeer added in v0.2.0

func (s *ClientPicker) PickPeer(key string) (PeerGetter, bool)

PickPeer pick a peer with the consistenthash algorithm

type Getter

type Getter interface {
	Get(key string) ([]byte, bool, time.Time)
}

Getter loads data for a key locally call back when a key cache missed impl by user

type GetterFunc

type GetterFunc func(key string) ([]byte, bool, time.Time)

func (GetterFunc) Get

func (f GetterFunc) Get(key string) ([]byte, bool, time.Time)

type Group

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

func GetGroup

func GetGroup(name string) *Group

func NewGroup

func NewGroup(name string, cacheBytes int64, getter Getter) *Group

NewGroup 新创建一个Group 如果存在同名的group会进行覆盖

func (*Group) Get

func (g *Group) Get(key string) (ByteView, error)

func (*Group) RegisterPeers

func (g *Group) RegisterPeers(peers PeerPicker)

type PeerGetter

type PeerGetter interface {
	Get(group string, key string) ([]byte, error)
}

PeerGetter must be implemented by a peer

type PeerPicker

type PeerPicker interface {
	PickPeer(key string) (peer PeerGetter, ok bool)
}

PeerPicker must be implemented to locate the peer that owns a specific key

type PickerOptions added in v0.2.0

type PickerOptions func(*ClientPicker)

func PickerServiceName added in v0.2.0

func PickerServiceName(serviceName string) PickerOptions

type Server

type Server struct {
	pb.UnimplementedGroupCacheServer
	// contains filtered or unexported fields
}

func NewServer

func NewServer(self string, opts ...ServerOptions) (*Server, error)

func (*Server) Get

func (s *Server) Get(ctx context.Context, in *pb.Request) (*pb.Response, error)

func (*Server) Log

func (s *Server) Log(format string, path ...interface{})

Log info

func (*Server) Start

func (s *Server) Start() error

func (*Server) Stop

func (s *Server) Stop()

type ServerOptions added in v0.2.0

type ServerOptions func(*Server)

func ServiceName added in v0.2.0

func ServiceName(sname string) ServerOptions

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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