zencached

package module
v1.13.1 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

README

Zencached - Advanced Memcached Client for Go

A high-performance, feature-rich memcached client library for Go with support for clustering, data compression, metrics collection, and automatic node rebalancing.

Table of Contents

Features

  • Memcached Protocol Support: Full implementation of memcached binary and text protocols via Telnet
  • Cluster Operations: Perform operations across multiple memcached nodes simultaneously
  • Data Compression: Optional compression of stored values (supports multiple compression types)
  • Metrics Collection: Built-in metrics for monitoring performance and operations
  • Node Rebalancing: Automatic node discovery and rebalancing with custom node listing functions
  • Connection Pooling: Maintains connection pools per node for optimal performance
  • Error Handling: Comprehensive error types with detailed context information
  • Context Support: Full context.Context support for timeout and cancellation control
  • Graceful Shutdown: Proper connection cleanup on shutdown

Installation

go get github.com/rnojiri/zencached

Quick Start

Basic Usage
package main

import (
    "context"
    "github.com/rnojiri/zencached"
)

func main() {
    // Create configuration
    config := &zencached.Configuration{
        Nodes: []zencached.Node{
            {Host: "localhost", Port: 11211},
            {Host: "localhost", Port: 11212},
        },
        NumConnectionsPerNode: 5,
    }

    // Create client
    client, err := zencached.New(config)
    if err != nil {
        panic(err)
    }
    defer client.Shutdown()

    // Set a value
    ctx := context.Background()
    result, err := client.Set(
        ctx,
        nil,                    // routerHash (optional)
        []byte("mypath"),       // path
        []byte("mykey"),        // key
        []byte("myvalue"),      // value
        3600,                   // TTL in seconds
    )
    if err != nil {
        panic(err)
    }

    // Get a value
    result, err = client.Get(ctx, nil, []byte("mypath"), []byte("mykey"))
    if err != nil {
        panic(err)
    }
    println("Value:", string(result.Data))

    // Delete a value
    client.Delete(ctx, nil, []byte("mypath"), []byte("mykey"))
}

Configuration

See Configuration Guide for detailed configuration options.

Basic Configuration Example
config := &zencached.Configuration{
    // Define memcached nodes
    Nodes: []zencached.Node{
        {Host: "memcached1", Port: 11211},
        {Host: "memcached2", Port: 11211},
    },

    // Connection settings
    NumConnectionsPerNode:      5,
    CommandExecutionBufferSize: 1000,

    // Node management
    RebalanceOnDisconnection: true,
    NumNodeListRetries:       3,
    NodeListRetryTimeout:     time.Second * 5,

    // Optional: Custom node listing function
    NodeListFunction: func() ([]zencached.Node, error) {
        // Fetch nodes from service discovery
        return getNodesFromServiceDiscovery()
    },

    // Optional: Compression
    CompressionType:  zencached.CompressionTypeZSTD,
    CompressionLevel: 3,

    // Optional: Metrics collection
    ZencachedMetricsCollector: myMetricsCollector,
}

client, err := zencached.New(config)

API Reference

Core Operations
Set(ctx context.Context, routerHash, path, key, value []byte, ttl uint64)

Sets a key-value pair. Creates or overwrites the value.

Add(ctx context.Context, routerHash, path, key, value []byte, ttl uint64)

Adds a key-value pair only if the key doesn't already exist.

Get(ctx context.Context, routerHash, path, key []byte)

Retrieves the value associated with a key.

Delete(ctx context.Context, routerHash, path, key []byte)

Deletes a key from the cache.

Cluster Operations
ClusterSet(ctx context.Context, path, key, value []byte, ttl uint64)

Sets a key-value pair on all nodes in the cluster.

ClusterAdd(ctx context.Context, path, key, value []byte, ttl uint64)

Adds a key-value pair on all nodes in the cluster.

ClusterGet(ctx context.Context, path, key []byte)

Retrieves a key from all nodes (useful for replicated data).

ClusterDelete(ctx context.Context, path, key []byte)

Deletes a key from all nodes in the cluster.

Node Management
Rebalance()

Triggers a rebalance of all nodes. Discovers nodes using the configured node listing function or uses static node configuration.

GetConnectedNodes() []Node

Returns the list of currently connected nodes.

Shutdown()

Gracefully shuts down all connections.

Advanced Features

Compression

Enable data compression to reduce network bandwidth and storage space:

config := &zencached.Configuration{
    CompressionType:  zencached.CompressionTypeZSTD,
    CompressionLevel: 3,
    // ... other config
}

Supported compression types:

  • CompressionTypeNone - No compression (default)
  • CompressionTypeZSTD - Zstandard compression (recommended)
Custom Node Discovery

Use a custom node listing function for dynamic node discovery:

config.NodeListFunction = func() ([]zencached.Node, error) {
    // Connect to service discovery (Consul, Kubernetes, etc.)
    nodes, err := consul.GetServiceNodes("memcached")
    if err != nil {
        return nil, err
    }
    return nodes, nil
}
Context Usage

All operations support context for timeout and cancellation:

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

result, err := client.Get(ctx, nil, []byte("path"), []byte("key"))

Metrics Collection

Implement the ZencachedMetricsCollector interface to collect metrics:

type MyMetricsCollector struct{}

func (m *MyMetricsCollector) CommandExecutionElapsedTime(node string, operation, path, key []byte, elapsedTime int64) {
    // Track command execution time
}

func (m *MyMetricsCollector) CommandExecution(node string, operation, path, key []byte) {
    // Track command execution
}

func (m *MyMetricsCollector) CommandExecutionError(node string, operation, path, key []byte, err error) {
    // Track command errors
}

func (m *MyMetricsCollector) CacheMissEvent(node string, operation, path, key []byte) {
    // Track cache misses
}

func (m *MyMetricsCollector) CacheHitEvent(node string, operation, path, key []byte) {
    // Track cache hits
}

// ... implement other required methods

config.ZencachedMetricsCollector = &MyMetricsCollector{}

See Metrics Reference for all available metrics hooks.

Error Handling

Zencached provides detailed error information:

result, err := client.Get(ctx, nil, []byte("path"), []byte("key"))
if err != nil {
    if ze, ok := err.(zencached.ZError); ok {
        errorCode := ze.Code()  // Get error type
        errorMsg := ze.String() // Get error message
    }
}

See Error Types for detailed error handling.

Examples

For comprehensive examples, see the Examples Guide:

  • Basic operations
  • Cluster operations
  • Compression
  • Metrics collection
  • Custom node discovery
  • Error handling
  • Context usage

Testing

Run tests:

go test -v ./...

Run benchmarks:

go test -bench=. ./...

Documentation

Complete documentation is available in the docs folder:

Contributing

Contributions are welcome! Please review the Contributing Guide for guidelines on code style, testing, and the pull request process.

License

See the LICENSE file for details.

Support

For issues, questions, or suggestions, please visit the project repository.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrInvalidKeyFormat - raised when a key has a invalid format
	ErrInvalidKeyFormat error = errors.New("key format is invalid, it should have more than 0 or maximum of 250 bytes without new lines and spaces")
)

memcached responses

View Source
var ErrUnknownCompressionType error = errors.New("unknown compression type")

Functions

func CompressionTypeStrings added in v1.9.0

func CompressionTypeStrings() []string

CompressionTypeStrings returns a slice of all String values of the enum

func ErrorTypeStrings added in v1.3.0

func ErrorTypeStrings() []string

ErrorTypeStrings returns a slice of all String values of the enum

func ResultTypeStrings added in v1.8.1

func ResultTypeStrings() []string

ResultTypeStrings returns a slice of all String values of the enum

func ValidateKey added in v1.8.2

func ValidateKey(path, key []byte) error

ValidateKey - validates a key

Types

type CompressionConfiguration added in v1.9.0

type CompressionConfiguration struct {
	CompressionType  CompressionType
	CompressionLevel int
}

CompressionConfiguration - compression configuration

type CompressionType added in v1.9.0

type CompressionType uint8
const (
	CompressionTypeNone CompressionType = iota
	CompressionTypeBase64
	CompressionTypeZstandard
)

func CompressionTypeString added in v1.9.0

func CompressionTypeString(s string) (CompressionType, error)

CompressionTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func CompressionTypeValues added in v1.9.0

func CompressionTypeValues() []CompressionType

CompressionTypeValues returns all values of the enum

func (CompressionType) IsACompressionType added in v1.9.0

func (i CompressionType) IsACompressionType() bool

IsACompressionType returns "true" if the value is listed in the enum definition. "false" otherwise

func (CompressionType) MarshalJSON added in v1.9.0

func (i CompressionType) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for CompressionType

func (CompressionType) MarshalText added in v1.9.0

func (i CompressionType) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for CompressionType

func (*CompressionType) Scan added in v1.9.0

func (i *CompressionType) Scan(value interface{}) error

func (CompressionType) String added in v1.9.0

func (i CompressionType) String() string

func (*CompressionType) UnmarshalJSON added in v1.9.0

func (i *CompressionType) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for CompressionType

func (*CompressionType) UnmarshalText added in v1.9.0

func (i *CompressionType) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for CompressionType

func (CompressionType) Value added in v1.9.0

func (i CompressionType) Value() (driver.Value, error)

type Configuration

type Configuration struct {
	// Nodes - the default memcached nodes
	Nodes []Node

	// NumConnectionsPerNode - the number of connections for each memcached node
	NumConnectionsPerNode int

	// CommandExecutionBufferSize - the number of command execution jobs buffered
	CommandExecutionBufferSize uint32

	// NumNodeListRetries - the number of node listing retry after an error
	NumNodeListRetries int

	// RebalanceOnDisconnection - always rebalance after some disconnection
	RebalanceOnDisconnection bool

	// ZencachedMetricsCollector - a metrics interface to implement metric extraction
	ZencachedMetricsCollector ZencachedMetricsCollector

	// NodeListFunction - a custom node listing function that can be customizable
	NodeListFunction GetNodeList

	// NodeListRetryTimeout - time to wait for node listing retry after an error
	NodeListRetryTimeout time.Duration

	// TimedMetricsPeriod - send metrics after some period (if metrics are enabled)
	TimedMetricsPeriod time.Duration

	// DisableTimedMetrics - disables the automatic sending of metrics (if metrics are enabled)
	DisableTimedMetrics bool

	TelnetConfiguration

	CompressionConfiguration
}

Configuration - has the main configuration

type DataCompressor added in v1.9.0

type DataCompressor interface {

	// Compress - compress the data
	Compress([]byte) ([]byte, error)

	// Decompress - decompress the data
	Decompress([]byte) ([]byte, error)
}

DataCompressor - compression implementation

func NewDataCompressor added in v1.9.0

func NewDataCompressor(ctype CompressionType, compressionLevel int) (DataCompressor, error)

NewDataCompressor - creates a new data copressor implementation

type ErrorType added in v1.3.0

type ErrorType uint8
const (
	ErrorTypeUndefined ErrorType = iota
	ErrorTypeMaxReconnectionsReached
	ErrorTypeMemcachedInvalidResponse
	ErrorTypeMemcachedNoResponse
	ErrorTypeTelnetConnectionIsClosed
	ErrorTypeNoAvailableNodes
	ErrorTypeNoAvailableConnections
	ErrorTypeConnectionWrite
	ErrorTypeConnectionRead
)

func ErrorTypeString added in v1.3.0

func ErrorTypeString(s string) (ErrorType, error)

ErrorTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func ErrorTypeValues added in v1.3.0

func ErrorTypeValues() []ErrorType

ErrorTypeValues returns all values of the enum

func (ErrorType) IsAErrorType added in v1.3.0

func (i ErrorType) IsAErrorType() bool

IsAErrorType returns "true" if the value is listed in the enum definition. "false" otherwise

func (ErrorType) MarshalJSON added in v1.3.0

func (i ErrorType) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for ErrorType

func (ErrorType) MarshalText added in v1.3.0

func (i ErrorType) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for ErrorType

func (*ErrorType) Scan added in v1.3.0

func (i *ErrorType) Scan(value interface{}) error

func (ErrorType) String added in v1.3.0

func (i ErrorType) String() string

func (*ErrorType) UnmarshalJSON added in v1.3.0

func (i *ErrorType) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for ErrorType

func (*ErrorType) UnmarshalText added in v1.3.0

func (i *ErrorType) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for ErrorType

func (ErrorType) Value added in v1.3.0

func (i ErrorType) Value() (driver.Value, error)

type GetNodeList added in v1.1.0

type GetNodeList func() ([]Node, error)

type IZencached

type IZencached interface {

	// Shutdown - closes all connections
	Shutdown()

	// Set - performs an storage set operation
	Set(ctx context.Context, routerHash, path, key, value []byte, ttl uint64) (*OperationResult, error)

	// Add - performs an storage add operation
	Add(ctx context.Context, routerHash, path, key, value []byte, ttl uint64) (*OperationResult, error)

	// Get - performs a get operation
	Get(ctx context.Context, routerHash, path, key []byte) (*OperationResult, error)

	// Delete - performs a delete operation
	Delete(ctx context.Context, routerHash, path, key []byte) (*OperationResult, error)

	// ClusterSet - performs an full storage set operation
	ClusterSet(ctx context.Context, path, key, value []byte, ttl uint64) ([]*OperationResult, []error)

	// ClusterAdd - performs an full storage add operation
	ClusterAdd(ctx context.Context, path, key, value []byte, ttl uint64) ([]*OperationResult, []error)

	// ClusterGet - returns a full replicated key stored in the cluster
	ClusterGet(ctx context.Context, path, key []byte) ([]*OperationResult, []error)

	// ClusterDelete - deletes a key from all cluster nodes
	ClusterDelete(ctx context.Context, path, key []byte) ([]*OperationResult, []error)

	// Rebalance - rebalance all nodes using the configured node listing function or the configured nodes by default
	Rebalance()

	// GetConnectedNodes - returns the currently connected nodes
	GetConnectedNodes() []Node
}

type MemcachedCommand

type MemcachedCommand []byte

MemcachedCommand type

var (
	// Add - add some key if it not exists
	Add MemcachedCommand = MemcachedCommand("add")

	// Set - sets a key if it exists or not
	Set MemcachedCommand = MemcachedCommand("set")

	// Get - return a key if it exists or not
	Get MemcachedCommand = MemcachedCommand("get")

	// Delete - deletes a key if it exists or not
	Delete MemcachedCommand = MemcachedCommand("delete")

	// Version - returns the server version
	Version MemcachedCommand = MemcachedCommand("version")
)

type Node

type Node struct {

	// Host - the server's hostname
	Host string

	// Port - the server's port
	Port int
}

Node - a memcached node

func (Node) String added in v1.3.0

func (n Node) String() string

String - returns a string under the format "host:port"

type OperationResult added in v1.8.0

type OperationResult struct {

	// Type - returns if the data was already stored
	Type ResultType

	// Data - the key content in bytes
	Data []byte

	// Node - node metadata
	Node Node
}

OperationResult - default operation results with metadata

type ResultType added in v1.8.1

type ResultType uint8
const (
	ResultTypeNone ResultType = iota
	ResultTypeError
	ResultTypeFound
	ResultTypeNotFound
	ResultTypeNotStored
	ResultTypeStored
	ResultTypeDeleted
	ResultTypeCompressionError
	ResultTypeDecompressionError
	ResultTypeContextTimeout
)

func ResultTypeString added in v1.8.1

func ResultTypeString(s string) (ResultType, error)

ResultTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func ResultTypeValues added in v1.8.1

func ResultTypeValues() []ResultType

ResultTypeValues returns all values of the enum

func (ResultType) IsAResultType added in v1.8.1

func (i ResultType) IsAResultType() bool

IsAResultType returns "true" if the value is listed in the enum definition. "false" otherwise

func (ResultType) MarshalJSON added in v1.8.1

func (i ResultType) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for ResultType

func (ResultType) MarshalText added in v1.8.1

func (i ResultType) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for ResultType

func (*ResultType) Scan added in v1.8.1

func (i *ResultType) Scan(value interface{}) error

func (ResultType) String added in v1.8.1

func (i ResultType) String() string

func (*ResultType) UnmarshalJSON added in v1.8.1

func (i *ResultType) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for ResultType

func (*ResultType) UnmarshalText added in v1.8.1

func (i *ResultType) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for ResultType

func (ResultType) Value added in v1.8.1

func (i ResultType) Value() (driver.Value, error)

type Telnet

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

Telnet - the telnet structure

func NewTelnet

func NewTelnet(node Node, configuration TelnetConfiguration, disconnectionChannel chan<- struct{}) (*Telnet, error)

NewTelnet - creates a new telnet connection

func (*Telnet) Close

func (t *Telnet) Close()

Close - closes the active connection

func (*Telnet) Connect

func (t *Telnet) Connect() error

Connect - try to Connect the telnet server

func (*Telnet) GetNode added in v1.3.0

func (t *Telnet) GetNode() Node

GetNode - returns this node

func (*Telnet) GetNodeHost added in v1.3.0

func (t *Telnet) GetNodeHost() string

GetNodeHost - returns this node host

func (*Telnet) Read

func (t *Telnet) Read(ctx context.Context, responseSet TelnetResponseSet) ([]byte, ResultType, error)

Read - reads the payload from the active connection

func (*Telnet) Send

func (t *Telnet) Send(ctx context.Context, command ...[]byte) error

Send - send some command to the server

type TelnetConfiguration

type TelnetConfiguration struct {

	// ReconnectionTimeout - the time duration between connection retries
	ReconnectionTimeout time.Duration

	// MaxWriteTimeout - the max time duration to wait a write operation
	MaxWriteTimeout time.Duration

	// MaxReadTimeout - the max time duration to wait a read operation
	MaxReadTimeout time.Duration

	// HostConnectionTimeout - the max time duration to wait to connect to a host
	HostConnectionTimeout time.Duration

	// ConnectionCheckTimeout - the max time duration to wait to check the host connection
	ConnectionCheckTimeout time.Duration

	// ConnectionCheckIdleWait - the time duration to wait when idle waiting for check connection timeout event
	ConnectionCheckIdleWait time.Duration

	// ReadBufferSize - the size of the read buffer in bytes
	ReadBufferSize int

	// EnableTracerLogs - enables tracer level logs
	EnableTracerLogs bool

	// TelnetMetricsCollector - collects metrics related with telnet
	TelnetMetricsCollector TelnetMetricsCollector
}

TelnetConfiguration - contains the telnet connection configuration

type TelnetMetricsCollector added in v1.3.0

type TelnetMetricsCollector interface {

	// ResolveAddressElapsedTime - the time took to resolve a name address (nanoseconds)
	ResolveAddressElapsedTime(node string, elapsedTime int64)

	// DialElapsedTime - the time took to dial to a node (nanoseconds)
	DialElapsedTime(node string, elapsedTime int64)

	// CloseElapsedTime - the time took to disconnect from a node (nanoseconds)
	CloseElapsedTime(node string, elapsedTime int64)

	// SendElapsedTime - the time took to send data (full process with dial and close if needed) (nanoseconds)
	SendElapsedTime(node string, elapsedTime int64)

	// WriteElapsedTime - the time took to write data (nanoseconds)
	WriteElapsedTime(node string, elapsedTime int64)

	// ReadElapsedTime - the time took to read data (nanoseconds)
	ReadElapsedTime(node string, elapsedTime int64)

	// ReadDataSize - data read size (bytes)
	ReadDataSize(node string, sizeInBytes int)

	// WriteDataSize - data write size (bytes)
	WriteDataSize(node string, sizeInBytes int)
}

TelnetMetricsCollector - the interface to collect metrics from telnet

type TelnetResponseSet added in v1.8.1

type TelnetResponseSet struct {
	ResponseSets [][]byte
	ResultTypes  []ResultType
}

type ZError added in v1.3.0

type ZError interface {
	error
	Code() ErrorType
	String() string
}
var (
	ErrMemcachedInvalidResponse ZError = NewError("invalid memcached command response received", ErrorTypeMemcachedInvalidResponse)
	ErrMemcachedNoResponse      ZError = NewError("no response from memcached", ErrorTypeMemcachedNoResponse)
	ErrTelnetConnectionIsClosed ZError = NewError("telnet connection is closed", ErrorTypeTelnetConnectionIsClosed)
	ErrNoAvailableNodes         ZError = NewError("there are no nodes available", ErrorTypeNoAvailableNodes)
	ErrConnectionWrite          ZError = NewError("error writing to connection", ErrorTypeConnectionWrite)
	ErrConnectionRead           ZError = NewError("error reading from connection", ErrorTypeConnectionRead)
)

func NewError added in v1.3.0

func NewError(msg string, et ErrorType) ZError

NewError - creates a new error

type ZErrorData added in v1.3.0

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

ZErrorData - a struc to store some metadata in the error to be an alternative to include zencached deps

func (ZErrorData) Code added in v1.3.0

func (e ZErrorData) Code() ErrorType

func (ZErrorData) Error added in v1.3.0

func (e ZErrorData) Error() string

func (ZErrorData) String added in v1.3.0

func (e ZErrorData) String() string

type Zencached

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

Zencached - declares the main structure

func New

func New(configuration *Configuration) (*Zencached, error)

New - creates a new instance

func (*Zencached) Add added in v1.2.0

func (z *Zencached) Add(ctx context.Context, routerHash, path, key, value []byte, ttl uint64) (*OperationResult, error)

Add - performs an storage add operation

func (*Zencached) ClusterAdd added in v1.2.0

func (z *Zencached) ClusterAdd(ctx context.Context, path, key, value []byte, ttl uint64) ([]*OperationResult, []error)

ClusterAdd - performs an full add operation operation

func (*Zencached) ClusterDelete

func (z *Zencached) ClusterDelete(ctx context.Context, path, key []byte) ([]*OperationResult, []error)

ClusterDelete - deletes a key from all cluster nodes

func (*Zencached) ClusterGet

func (z *Zencached) ClusterGet(ctx context.Context, path, key []byte) ([]*OperationResult, []error)

ClusterGet - returns a full replicated key stored in the cluster

func (*Zencached) ClusterSet added in v1.2.0

func (z *Zencached) ClusterSet(ctx context.Context, path, key, value []byte, ttl uint64) ([]*OperationResult, []error)

ClusterSet - performs an full set operation operation

func (*Zencached) Delete

func (z *Zencached) Delete(ctx context.Context, routerHash, path, key []byte) (*OperationResult, error)

Delete - performs a delete operation

func (*Zencached) Get

func (z *Zencached) Get(ctx context.Context, routerHash, path, key []byte) (*OperationResult, error)

Get - performs a get operation

func (*Zencached) GetConnectedNodeWorkers added in v1.3.0

func (z *Zencached) GetConnectedNodeWorkers(routerHash, path, key []byte) (nw *nodeWorkers, index int, err error)

GetConnectedNodeWorkers - returns an idle telnet connection

func (*Zencached) GetConnectedNodes added in v1.2.0

func (z *Zencached) GetConnectedNodes() []Node

GetConnectedNodes - returns the currently connected nodes

func (*Zencached) GetNodeWorkersByIndex added in v1.3.0

func (z *Zencached) GetNodeWorkersByIndex(index int) (nw *nodeWorkers, err error)

GetNodeWorkersByIndex - returns a telnet connection by node index

func (*Zencached) Rebalance added in v1.1.0

func (z *Zencached) Rebalance()

Rebalance - rebalance all nodes

func (*Zencached) Set added in v1.2.0

func (z *Zencached) Set(ctx context.Context, routerHash, path, key, value []byte, ttl uint64) (*OperationResult, error)

Set - performs an storage set operation

func (*Zencached) Shutdown

func (z *Zencached) Shutdown()

Shutdown - closes all connections

func (*Zencached) Version added in v1.3.0

func (z *Zencached) Version(ctx context.Context, routerHash []byte) (*OperationResult, error)

Version - performs a version operation

type ZencachedMetricsCollector added in v1.3.0

type ZencachedMetricsCollector interface {

	// CommandExecutionElapsedTime - command execution elapsed time
	CommandExecutionElapsedTime(node string, operation, path, key []byte, elapsedTime int64)

	// CommandExecution - an memcached command event
	CommandExecution(node string, operation, path, key []byte)

	// CommandExecutionError - signalizes an error executing a command (cast to the ZError interface to get extra metadata)
	CommandExecutionError(node string, operation, path, key []byte, err error)

	// CacheMissEvent - signalizes a cache miss event
	CacheMissEvent(node string, operation, path, key []byte)

	// CacheHitEvent - signalizes a cache hit event
	CacheHitEvent(node string, operation, path, key []byte)

	// NodeRebalanceEvent - signalizes a node rebalance event
	NodeRebalanceEvent(numNodes int)

	// NodeListingEvent - signalizes a node listing event
	NodeListingEvent(numNodes int)

	// NodeListingError - signalizes a node listing error
	NodeListingError()

	// NodeListingElapsedTime - signalizes a node listing elapsed time (nanoseconds)
	NodeListingElapsedTime(elapsedTime int64)

	// NodeRebalanceElapsedTime - signalizes a node rebalance event (nanoseconds)
	NodeRebalanceElapsedTime(elapsedTime int64)
}

ZencachedMetricsCollector - the interface to collect metrics from zencached

Jump to

Keyboard shortcuts

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