Documentation
¶
Index ¶
- Variables
- type Cluster
- func (c *Cluster) Add(key string, value []byte, flags uint32, ttlSeconds int) error
- func (c *Cluster) AddNoContext(key string, value []byte, flags uint32, ttlSeconds int) error
- func (c *Cluster) AddWithContext(ctx context.Context, key string, value []byte, flags uint32, ttlSeconds int) error
- func (c *Cluster) Append(key string, value []byte) error
- func (c *Cluster) AppendNoContext(key string, value []byte) error
- func (c *Cluster) AppendWithContext(ctx context.Context, key string, value []byte) error
- func (c *Cluster) CAS(key string, value []byte, flags uint32, ttlSeconds int, cas uint64) error
- func (c *Cluster) CASNoContext(key string, value []byte, flags uint32, ttlSeconds int, cas uint64) error
- func (c *Cluster) CASWithContext(ctx context.Context, key string, value []byte, flags uint32, ttlSeconds int, ...) error
- func (c *Cluster) Close() error
- func (c *Cluster) Decr(key string, delta uint64) (uint64, error)
- func (c *Cluster) DecrNoContext(key string, delta uint64) (uint64, error)
- func (c *Cluster) DecrWithContext(ctx context.Context, key string, delta uint64) (uint64, error)
- func (c *Cluster) Delete(key string) error
- func (c *Cluster) DeleteNoContext(key string) error
- func (c *Cluster) DeleteWithContext(ctx context.Context, key string) error
- func (c *Cluster) FlushAll() error
- func (c *Cluster) FlushAllNoContext() error
- func (c *Cluster) FlushAllWithContext(ctx context.Context) error
- func (c *Cluster) Get(key string) (*mcturbo.Item, error)
- func (c *Cluster) GetAndTouch(key string, ttlSeconds int) (*mcturbo.Item, error)
- func (c *Cluster) GetAndTouchNoContext(key string, ttlSeconds int) (*mcturbo.Item, error)
- func (c *Cluster) GetAndTouchWithContext(ctx context.Context, key string, ttlSeconds int) (*mcturbo.Item, error)
- func (c *Cluster) GetMulti(keys []string) (map[string]*mcturbo.Item, error)
- func (c *Cluster) GetMultiWithContext(ctx context.Context, keys []string) (map[string]*mcturbo.Item, error)
- func (c *Cluster) GetNoContext(key string) (*mcturbo.Item, error)
- func (c *Cluster) GetWithContext(ctx context.Context, key string) (*mcturbo.Item, error)
- func (c *Cluster) Gets(key string) (*mcturbo.Item, error)
- func (c *Cluster) GetsNoContext(key string) (*mcturbo.Item, error)
- func (c *Cluster) GetsWithContext(ctx context.Context, key string) (*mcturbo.Item, error)
- func (c *Cluster) Incr(key string, delta uint64) (uint64, error)
- func (c *Cluster) IncrNoContext(key string, delta uint64) (uint64, error)
- func (c *Cluster) IncrWithContext(ctx context.Context, key string, delta uint64) (uint64, error)
- func (c *Cluster) Ping() error
- func (c *Cluster) PingNoContext() error
- func (c *Cluster) PingWithContext(ctx context.Context) error
- func (c *Cluster) Prepend(key string, value []byte) error
- func (c *Cluster) PrependNoContext(key string, value []byte) error
- func (c *Cluster) PrependWithContext(ctx context.Context, key string, value []byte) error
- func (c *Cluster) Replace(key string, value []byte, flags uint32, ttlSeconds int) error
- func (c *Cluster) ReplaceNoContext(key string, value []byte, flags uint32, ttlSeconds int) error
- func (c *Cluster) ReplaceWithContext(ctx context.Context, key string, value []byte, flags uint32, ttlSeconds int) error
- func (c *Cluster) Set(key string, value []byte, flags uint32, ttlSeconds int) error
- func (c *Cluster) SetNoContext(key string, value []byte, flags uint32, ttlSeconds int) error
- func (c *Cluster) SetWithContext(ctx context.Context, key string, value []byte, flags uint32, ttlSeconds int) error
- func (c *Cluster) Touch(key string, ttlSeconds int) error
- func (c *Cluster) TouchNoContext(key string, ttlSeconds int) error
- func (c *Cluster) TouchWithContext(ctx context.Context, key string, ttlSeconds int) error
- func (c *Cluster) UpdateServers(servers []Server) error
- type ClusterOption
- func WithBaseClientOptions(opts ...mcturbo.Option) ClusterOption
- func WithDistribution(d Distribution) ClusterOption
- func WithHash(h Hash) ClusterOption
- func WithLibketamaCompatible(enabled bool) ClusterOption
- func WithRemoveFailedServers(enabled bool) ClusterOption
- func WithRetryTimeout(d time.Duration) ClusterOption
- func WithRouterFactory(f RouterFactory) ClusterOption
- func WithServerFailureLimit(n int) ClusterOption
- func WithVnodeFactor(n int) ClusterOption
- type Distribution
- type Hash
- type Router
- type RouterFactory
- type Server
Constants ¶
This section is empty.
Variables ¶
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) AddNoContext ¶ added in v0.0.2
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) AppendNoContext ¶ added in v0.0.2
AppendNoContext is an explicit no-context alias of Append.
func (*Cluster) AppendWithContext ¶ added in v0.0.2
AppendWithContext appends value to existing key value.
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) Decr ¶ added in v0.0.2
Decr decrements a numeric value by delta and returns the new value.
func (*Cluster) DecrNoContext ¶ added in v0.0.2
DecrNoContext is an explicit no-context alias of Decr.
func (*Cluster) DecrWithContext ¶ added in v0.0.2
DecrWithContext decrements a numeric value by delta and returns the new value.
func (*Cluster) DeleteNoContext ¶
DeleteNoContext is an explicit no-context alias of Delete.
func (*Cluster) DeleteWithContext ¶
DeleteWithContext removes key using ctx.
func (*Cluster) FlushAllNoContext ¶ added in v0.0.2
FlushAllNoContext is an explicit no-context alias of FlushAll.
func (*Cluster) FlushAllWithContext ¶ added in v0.0.2
FlushAllWithContext removes all keys on all shards using ctx.
func (*Cluster) GetAndTouch ¶ added in v0.0.2
GetAndTouch gets key and updates key expiration to ttlSeconds.
func (*Cluster) GetAndTouchNoContext ¶ added in v0.0.2
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
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 ¶
GetNoContext is an explicit no-context alias of Get.
func (*Cluster) GetWithContext ¶
GetWithContext returns the value for key using ctx.
func (*Cluster) GetsNoContext ¶ added in v0.0.2
GetsNoContext is an explicit no-context alias of Gets.
func (*Cluster) GetsWithContext ¶ added in v0.0.2
GetsWithContext returns the item for key with CAS value using ctx.
func (*Cluster) Incr ¶ added in v0.0.2
Incr increments a numeric value by delta and returns the new value.
func (*Cluster) IncrNoContext ¶ added in v0.0.2
IncrNoContext is an explicit no-context alias of Incr.
func (*Cluster) IncrWithContext ¶ added in v0.0.2
IncrWithContext increments a numeric value by delta and returns the new value.
func (*Cluster) PingNoContext ¶ added in v0.0.2
PingNoContext is an explicit no-context alias of Ping.
func (*Cluster) PingWithContext ¶ added in v0.0.2
PingWithContext checks connectivity against all shards using ctx.
func (*Cluster) PrependNoContext ¶ added in v0.0.2
PrependNoContext is an explicit no-context alias of Prepend.
func (*Cluster) PrependWithContext ¶ added in v0.0.2
PrependWithContext prepends value to existing key value.
func (*Cluster) ReplaceNoContext ¶ added in v0.0.2
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) SetNoContext ¶
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) TouchNoContext ¶
TouchNoContext is an explicit no-context alias of Touch.
func (*Cluster) TouchWithContext ¶
TouchWithContext updates key expiration using ctx.
func (*Cluster) UpdateServers ¶
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 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 Router ¶
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.