proxy

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const RandomMaxValues uint64 = 1000000

RandomMaxValues random from 0 => 999,999

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config[S ServerConfig] struct {
	Servers []S
	Route   Route
}

Config ...

type Memcache

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

Memcache is thread safe

func New

func New[S ServerConfig](
	conf Config[S],
	newFunc func(conf S) memproxy.Memcache,
	options ...MemcacheOption,
) (*Memcache, error)

New ...

func NewSimpleReplicatedMemcache

func NewSimpleReplicatedMemcache(
	servers []SimpleServerConfig,
	numConnsPerServer int,
	stats ServerStats,
	options ...ReplicatedRouteOption,
) (*Memcache, func(), error)

NewSimpleReplicatedMemcache ...

func (*Memcache) Close

func (m *Memcache) Close() error

Close ...

func (*Memcache) Pipeline

func (m *Memcache) Pipeline(
	ctx context.Context, options ...memproxy.PipelineOption,
) memproxy.Pipeline

Pipeline ...

type MemcacheOption

type MemcacheOption func(conf *memcacheConfig)

MemcacheOption ...

func WithMemcacheSessionProvider

func WithMemcacheSessionProvider(provider memproxy.SessionProvider) MemcacheOption

WithMemcacheSessionProvider ...

type Pipeline

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

Pipeline is NOT thread safe

func (*Pipeline) Delete

func (p *Pipeline) Delete(
	key string, options memproxy.DeleteOptions,
) func() (memproxy.DeleteResponse, error)

Delete ...

func (*Pipeline) Execute

func (p *Pipeline) Execute()

Execute ...

func (*Pipeline) Finish

func (p *Pipeline) Finish()

Finish ...

func (*Pipeline) LeaseGet

func (p *Pipeline) LeaseGet(
	key string, options memproxy.LeaseGetOptions,
) memproxy.LeaseGetResult

LeaseGet ...

func (*Pipeline) LeaseSet

func (p *Pipeline) LeaseSet(
	key string, data []byte, cas uint64,
	options memproxy.LeaseSetOptions,
) func() (memproxy.LeaseSetResponse, error)

LeaseSet ...

func (*Pipeline) LowerSession

func (p *Pipeline) LowerSession() memproxy.Session

LowerSession returns a lower priority session

type ReplicatedRouteOption

type ReplicatedRouteOption func(conf *replicatedRouteConfig)

ReplicatedRouteOption ...

func WithMemoryScoringFunc added in v0.5.0

func WithMemoryScoringFunc(memScoreFunc func(mem float64) float64) ReplicatedRouteOption

WithMemoryScoringFunc changes the weight function for replication load-balancing

func WithMinPercentage

func WithMinPercentage(percentage float64) ReplicatedRouteOption

WithMinPercentage minimum request percentage to memcached servers

func WithRandFunc

func WithRandFunc(randFunc func(n uint64) uint64) ReplicatedRouteOption

WithRandFunc ...

type Route

type Route interface {
	// NewSelector ...
	NewSelector() Selector

	// AllServerIDs returns list of all possible server ids
	AllServerIDs() []ServerID
}

Route must be Thread Safe

func NewReplicatedRoute

func NewReplicatedRoute(
	servers []ServerID,
	stats ServerStats,
	options ...ReplicatedRouteOption,
) Route

NewReplicatedRoute ...

type Selector

type Selector interface {
	// SetFailedServer ...
	SetFailedServer(server ServerID)

	// HasNextAvailableServer check if next available server ready to be fallback to
	HasNextAvailableServer() bool

	// SelectServer choose a server id, will keep in this server id unless Reset is call or failed server added
	SelectServer(key string) ServerID

	// SelectForDelete choose servers for deleting
	SelectForDelete(key string) []ServerID

	// Reset the selection
	Reset()
}

Selector is NOT thread safe

type ServerConfig

type ServerConfig interface {
	// GetID returns the server id, must be unique
	GetID() ServerID
}

ServerConfig is a constraint for server config type

type ServerID

type ServerID int

ServerID ...

type ServerStats

type ServerStats interface {
	// IsServerFailed check whether the server is currently not connected
	IsServerFailed(server ServerID) bool

	// NotifyServerFailed ...
	NotifyServerFailed(server ServerID)

	// GetMemUsage returns memory usage in bytes
	GetMemUsage(server ServerID) float64
}

ServerStats is thread safe

type SimpleServerConfig

type SimpleServerConfig struct {
	ID   ServerID
	Host string
	Port uint16
}

SimpleServerConfig ...

func (SimpleServerConfig) Address

func (c SimpleServerConfig) Address() string

Address ...

func (SimpleServerConfig) GetID

func (c SimpleServerConfig) GetID() ServerID

GetID ...

type SimpleServerStats

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

SimpleServerStats ...

func NewSimpleServerStats

func NewSimpleServerStats[S ServerConfig](
	servers []S,
	factory func(conf S) StatsClient,
	options ...SimpleStatsOption,
) *SimpleServerStats

NewSimpleServerStats ...

func NewSimpleStats

func NewSimpleStats(servers []SimpleServerConfig, options ...SimpleStatsOption) *SimpleServerStats

NewSimpleStats ...

func (*SimpleServerStats) GetMemUsage

func (s *SimpleServerStats) GetMemUsage(server ServerID) float64

GetMemUsage returns memory usage in bytes

func (*SimpleServerStats) IsServerFailed

func (s *SimpleServerStats) IsServerFailed(server ServerID) bool

IsServerFailed check whether the server is currently not connected

func (*SimpleServerStats) NotifyServerFailed

func (s *SimpleServerStats) NotifyServerFailed(server ServerID)

NotifyServerFailed ...

func (*SimpleServerStats) Shutdown

func (s *SimpleServerStats) Shutdown()

Shutdown ...

type SimpleStatsOption

type SimpleStatsOption func(conf *simpleStatsConfig)

SimpleStatsOption ...

func WithSimpleStatsCheckDuration

func WithSimpleStatsCheckDuration(d time.Duration) SimpleStatsOption

WithSimpleStatsCheckDuration ...

func WithSimpleStatsErrorLogger

func WithSimpleStatsErrorLogger(logger func(err error)) SimpleStatsOption

WithSimpleStatsErrorLogger ...

func WithSimpleStatsMemLogger

func WithSimpleStatsMemLogger(memLogger func(server ServerID, mem uint64, err error)) SimpleStatsOption

WithSimpleStatsMemLogger ...

type StatsClient

type StatsClient interface {
	// GetMemUsage get memory usage in bytes
	GetMemUsage() (uint64, error)

	// Close client
	Close() error
}

StatsClient ...

func NewSimpleStatsClient

func NewSimpleStatsClient(conf SimpleServerConfig) StatsClient

NewSimpleStatsClient ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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