cluster

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrClosed is returned when the cluster is already closed.
	ErrClosed = errors.New("cluster: closed")
)

Functions

This section is empty.

Types

type Cluster

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

Cluster routes keys to shard clients built from mcturbo.Client.

func NewCluster

func NewCluster(servers []Server, opts ...ClusterOption) (*Cluster, error)

NewCluster creates a new distributed client from servers.

func (*Cluster) Add added in v0.0.2

func (c *Cluster) Add(key string, value []byte, flags uint32, ttlSeconds int) error

Add stores value for key only if key does not exist.

func (*Cluster) AddNoContext added in v0.0.2

func (c *Cluster) AddNoContext(key string, value []byte, flags uint32, ttlSeconds int) error

AddNoContext is an explicit no-context alias of Add.

func (*Cluster) AddWithContext added in v0.0.2

func (c *Cluster) AddWithContext(ctx context.Context, key string, value []byte, flags uint32, ttlSeconds int) error

AddWithContext stores value for key only if key does not exist.

func (*Cluster) Append added in v0.0.2

func (c *Cluster) Append(key string, value []byte) error

Append appends value to existing key value.

func (*Cluster) AppendNoContext added in v0.0.2

func (c *Cluster) AppendNoContext(key string, value []byte) error

AppendNoContext is an explicit no-context alias of Append.

func (*Cluster) AppendWithContext added in v0.0.2

func (c *Cluster) AppendWithContext(ctx context.Context, key string, value []byte) error

AppendWithContext appends value to existing key value.

func (*Cluster) CAS added in v0.0.2

func (c *Cluster) CAS(key string, value []byte, flags uint32, ttlSeconds int, cas uint64) error

CAS stores value for key only when cas matches.

func (*Cluster) CASNoContext added in v0.0.2

func (c *Cluster) CASNoContext(key string, value []byte, flags uint32, ttlSeconds int, cas uint64) error

CASNoContext is an explicit no-context alias of CAS.

func (*Cluster) CASWithContext added in v0.0.2

func (c *Cluster) CASWithContext(ctx context.Context, key string, value []byte, flags uint32, ttlSeconds int, cas uint64) error

CASWithContext stores value for key only when cas matches using ctx.

func (*Cluster) Close

func (c *Cluster) Close() error

Close closes all shard clients.

func (*Cluster) Decr added in v0.0.2

func (c *Cluster) Decr(key string, delta uint64) (uint64, error)

Decr decrements a numeric value by delta and returns the new value.

func (*Cluster) DecrNoContext added in v0.0.2

func (c *Cluster) DecrNoContext(key string, delta uint64) (uint64, error)

DecrNoContext is an explicit no-context alias of Decr.

func (*Cluster) DecrWithContext added in v0.0.2

func (c *Cluster) DecrWithContext(ctx context.Context, key string, delta uint64) (uint64, error)

DecrWithContext decrements a numeric value by delta and returns the new value.

func (*Cluster) Delete

func (c *Cluster) Delete(key string) error

Delete removes key.

func (*Cluster) DeleteNoContext

func (c *Cluster) DeleteNoContext(key string) error

DeleteNoContext is an explicit no-context alias of Delete.

func (*Cluster) DeleteWithContext

func (c *Cluster) DeleteWithContext(ctx context.Context, key string) error

DeleteWithContext removes key using ctx.

func (*Cluster) FlushAll added in v0.0.2

func (c *Cluster) FlushAll() error

FlushAll removes all keys on all shards.

func (*Cluster) FlushAllNoContext added in v0.0.2

func (c *Cluster) FlushAllNoContext() error

FlushAllNoContext is an explicit no-context alias of FlushAll.

func (*Cluster) FlushAllWithContext added in v0.0.2

func (c *Cluster) FlushAllWithContext(ctx context.Context) error

FlushAllWithContext removes all keys on all shards using ctx.

func (*Cluster) Get

func (c *Cluster) Get(key string) (*mcturbo.Item, error)

Get returns the value for key.

func (*Cluster) GetAndTouch added in v0.0.2

func (c *Cluster) GetAndTouch(key string, ttlSeconds int) (*mcturbo.Item, error)

GetAndTouch gets key and updates key expiration to ttlSeconds.

func (*Cluster) GetAndTouchNoContext added in v0.0.2

func (c *Cluster) GetAndTouchNoContext(key string, ttlSeconds int) (*mcturbo.Item, error)

GetAndTouchNoContext is an explicit no-context alias of GetAndTouch.

func (*Cluster) GetAndTouchWithContext added in v0.0.2

func (c *Cluster) GetAndTouchWithContext(ctx context.Context, key string, ttlSeconds int) (*mcturbo.Item, error)

GetAndTouchWithContext gets key and updates key expiration to ttlSeconds.

func (*Cluster) GetMulti added in v0.0.2

func (c *Cluster) GetMulti(keys []string) (map[string]*mcturbo.Item, error)

GetMulti fetches multiple keys from routed shards without context.

func (*Cluster) GetMultiWithContext added in v0.0.2

func (c *Cluster) GetMultiWithContext(ctx context.Context, keys []string) (map[string]*mcturbo.Item, error)

GetMultiWithContext fetches multiple keys from routed shards using ctx.

func (*Cluster) GetNoContext

func (c *Cluster) GetNoContext(key string) (*mcturbo.Item, error)

GetNoContext is an explicit no-context alias of Get.

func (*Cluster) GetWithContext

func (c *Cluster) GetWithContext(ctx context.Context, key string) (*mcturbo.Item, error)

GetWithContext returns the value for key using ctx.

func (*Cluster) Gets added in v0.0.2

func (c *Cluster) Gets(key string) (*mcturbo.Item, error)

Gets returns the item for key with CAS value.

func (*Cluster) GetsNoContext added in v0.0.2

func (c *Cluster) GetsNoContext(key string) (*mcturbo.Item, error)

GetsNoContext is an explicit no-context alias of Gets.

func (*Cluster) GetsWithContext added in v0.0.2

func (c *Cluster) GetsWithContext(ctx context.Context, key string) (*mcturbo.Item, error)

GetsWithContext returns the item for key with CAS value using ctx.

func (*Cluster) Incr added in v0.0.2

func (c *Cluster) Incr(key string, delta uint64) (uint64, error)

Incr increments a numeric value by delta and returns the new value.

func (*Cluster) IncrNoContext added in v0.0.2

func (c *Cluster) IncrNoContext(key string, delta uint64) (uint64, error)

IncrNoContext is an explicit no-context alias of Incr.

func (*Cluster) IncrWithContext added in v0.0.2

func (c *Cluster) IncrWithContext(ctx context.Context, key string, delta uint64) (uint64, error)

IncrWithContext increments a numeric value by delta and returns the new value.

func (*Cluster) Ping added in v0.0.2

func (c *Cluster) Ping() error

Ping checks connectivity against all shards.

func (*Cluster) PingNoContext added in v0.0.2

func (c *Cluster) PingNoContext() error

PingNoContext is an explicit no-context alias of Ping.

func (*Cluster) PingWithContext added in v0.0.2

func (c *Cluster) PingWithContext(ctx context.Context) error

PingWithContext checks connectivity against all shards using ctx.

func (*Cluster) Prepend added in v0.0.2

func (c *Cluster) Prepend(key string, value []byte) error

Prepend prepends value to existing key value.

func (*Cluster) PrependNoContext added in v0.0.2

func (c *Cluster) PrependNoContext(key string, value []byte) error

PrependNoContext is an explicit no-context alias of Prepend.

func (*Cluster) PrependWithContext added in v0.0.2

func (c *Cluster) PrependWithContext(ctx context.Context, key string, value []byte) error

PrependWithContext prepends value to existing key value.

func (*Cluster) Replace added in v0.0.2

func (c *Cluster) Replace(key string, value []byte, flags uint32, ttlSeconds int) error

Replace stores value for key only if key already exists.

func (*Cluster) ReplaceNoContext added in v0.0.2

func (c *Cluster) ReplaceNoContext(key string, value []byte, flags uint32, ttlSeconds int) error

ReplaceNoContext is an explicit no-context alias of Replace.

func (*Cluster) ReplaceWithContext added in v0.0.2

func (c *Cluster) ReplaceWithContext(ctx context.Context, key string, value []byte, flags uint32, ttlSeconds int) error

ReplaceWithContext stores value for key only if key already exists.

func (*Cluster) Set

func (c *Cluster) Set(key string, value []byte, flags uint32, ttlSeconds int) error

Set stores value for key with flags and ttlSeconds.

func (*Cluster) SetNoContext

func (c *Cluster) SetNoContext(key string, value []byte, flags uint32, ttlSeconds int) error

SetNoContext is an explicit no-context alias of Set.

func (*Cluster) SetWithContext

func (c *Cluster) SetWithContext(ctx context.Context, key string, value []byte, flags uint32, ttlSeconds int) error

SetWithContext stores value for key with flags and ttlSeconds using ctx.

func (*Cluster) Touch

func (c *Cluster) Touch(key string, ttlSeconds int) error

Touch updates key expiration to ttlSeconds.

func (*Cluster) TouchNoContext

func (c *Cluster) TouchNoContext(key string, ttlSeconds int) error

TouchNoContext is an explicit no-context alias of Touch.

func (*Cluster) TouchWithContext

func (c *Cluster) TouchWithContext(ctx context.Context, key string, ttlSeconds int) error

TouchWithContext updates key expiration using ctx.

func (*Cluster) UpdateServers

func (c *Cluster) UpdateServers(servers []Server) error

UpdateServers updates cluster servers and rebuilds routing.

type ClusterOption

type ClusterOption func(*clusterConfig) error

ClusterOption configures Cluster behavior.

func WithBaseClientOptions

func WithBaseClientOptions(opts ...mcturbo.Option) ClusterOption

WithBaseClientOptions applies base mcturbo options to all shard clients.

func WithDistribution

func WithDistribution(d Distribution) ClusterOption

WithDistribution sets key distribution strategy.

func WithHash

func WithHash(h Hash) ClusterOption

WithHash sets key hash algorithm.

func WithLibketamaCompatible

func WithLibketamaCompatible(enabled bool) ClusterOption

WithLibketamaCompatible enables libketama-compatible behavior. When enabled, distribution is forced to consistent and hash is forced to MD5.

func WithRemoveFailedServers added in v0.0.2

func WithRemoveFailedServers(enabled bool) ClusterOption

WithRemoveFailedServers enables temporary auto-eject on communication failures.

func WithRetryTimeout added in v0.0.2

func WithRetryTimeout(d time.Duration) ClusterOption

WithRetryTimeout sets how long an ejected server stays out of the ring.

func WithRouterFactory added in v0.0.3

func WithRouterFactory(f RouterFactory) ClusterOption

WithRouterFactory sets a custom router builder used by NewCluster and UpdateServers.

func WithServerFailureLimit added in v0.0.2

func WithServerFailureLimit(n int) ClusterOption

WithServerFailureLimit sets failures before a server is temporarily ejected.

func WithVnodeFactor

func WithVnodeFactor(n int) ClusterOption

WithVnodeFactor sets virtual-node factor for consistent hashing.

type Distribution

type Distribution uint8

Distribution controls key-to-shard routing strategy.

const (
	// DistributionDefault uses the package default distribution.
	DistributionDefault Distribution = iota
	// DistributionModula maps keys by hash(key) % serverCount.
	DistributionModula
	// DistributionConsistent maps keys with a consistent-hash ring.
	DistributionConsistent
)

type Hash

type Hash uint8

Hash controls key hashing algorithm.

const (
	// HashDefault uses the package default hash.
	HashDefault Hash = iota
	// HashMD5 uses MD5-based hashing.
	HashMD5
	// HashCRC32 uses CRC32 hashing.
	HashCRC32
)

type Router

type Router interface {
	Pick(key string) int
}

Router decides shard index from a key.

func DefaultRouterFactory added in v0.0.3

func DefaultRouterFactory(servers []Server, distribution Distribution, hash Hash, vnodeFactor int) (Router, error)

DefaultRouterFactory is the built-in router builder used when no custom factory is set.

type RouterFactory added in v0.0.3

type RouterFactory func(servers []Server, distribution Distribution, hash Hash, vnodeFactor int) (Router, error)

RouterFactory builds a router from server list and routing settings.

func ConsistentRouterFactory added in v0.0.3

func ConsistentRouterFactory(hash Hash, vnodeFactor int) RouterFactory

ConsistentRouterFactory returns a built-in RouterFactory fixed to consistent distribution.

func ModulaRouterFactory added in v0.0.3

func ModulaRouterFactory(hash Hash) RouterFactory

ModulaRouterFactory returns a built-in RouterFactory fixed to modula distribution.

type Server

type Server struct {
	// Addr is the server address, for example "127.0.0.1:11211".
	Addr string
	// Weight controls shard share for consistent hashing.
	Weight int
}

Server defines one memcached server in the cluster.

Jump to

Keyboard shortcuts

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