Documentation
¶
Index ¶
- Variables
- func CompressionTypeStrings() []string
- func ErrorTypeStrings() []string
- func ResultTypeStrings() []string
- func ValidateKey(path, key []byte) error
- type CompressionConfiguration
- type CompressionType
- func (i CompressionType) IsACompressionType() bool
- func (i CompressionType) MarshalJSON() ([]byte, error)
- func (i CompressionType) MarshalText() ([]byte, error)
- func (i *CompressionType) Scan(value interface{}) error
- func (i CompressionType) String() string
- func (i *CompressionType) UnmarshalJSON(data []byte) error
- func (i *CompressionType) UnmarshalText(text []byte) error
- func (i CompressionType) Value() (driver.Value, error)
- type Configuration
- type DataCompressor
- type ErrorType
- func (i ErrorType) IsAErrorType() bool
- func (i ErrorType) MarshalJSON() ([]byte, error)
- func (i ErrorType) MarshalText() ([]byte, error)
- func (i *ErrorType) Scan(value interface{}) error
- func (i ErrorType) String() string
- func (i *ErrorType) UnmarshalJSON(data []byte) error
- func (i *ErrorType) UnmarshalText(text []byte) error
- func (i ErrorType) Value() (driver.Value, error)
- type GetNodeList
- type IZencached
- type MemcachedCommand
- type Node
- type OperationResult
- type ResultType
- func (i ResultType) IsAResultType() bool
- func (i ResultType) MarshalJSON() ([]byte, error)
- func (i ResultType) MarshalText() ([]byte, error)
- func (i *ResultType) Scan(value interface{}) error
- func (i ResultType) String() string
- func (i *ResultType) UnmarshalJSON(data []byte) error
- func (i *ResultType) UnmarshalText(text []byte) error
- func (i ResultType) Value() (driver.Value, error)
- type Telnet
- type TelnetConfiguration
- type TelnetMetricsCollector
- type TelnetResponseSet
- type ZError
- type ZErrorData
- type Zencached
- func (z *Zencached) Add(ctx context.Context, routerHash, path, key, value []byte, ttl uint64) (*OperationResult, error)
- func (z *Zencached) ClusterAdd(ctx context.Context, path, key, value []byte, ttl uint64) ([]*OperationResult, []error)
- func (z *Zencached) ClusterDelete(ctx context.Context, path, key []byte) ([]*OperationResult, []error)
- func (z *Zencached) ClusterGet(ctx context.Context, path, key []byte) ([]*OperationResult, []error)
- func (z *Zencached) ClusterSet(ctx context.Context, path, key, value []byte, ttl uint64) ([]*OperationResult, []error)
- func (z *Zencached) Delete(ctx context.Context, routerHash, path, key []byte) (*OperationResult, error)
- func (z *Zencached) Get(ctx context.Context, routerHash, path, key []byte) (*OperationResult, error)
- func (z *Zencached) GetConnectedNodeWorkers(routerHash, path, key []byte) (nw *nodeWorkers, index int, err error)
- func (z *Zencached) GetConnectedNodes() []Node
- func (z *Zencached) GetNodeWorkersByIndex(index int) (nw *nodeWorkers, err error)
- func (z *Zencached) Rebalance()
- func (z *Zencached) Set(ctx context.Context, routerHash, path, key, value []byte, ttl uint64) (*OperationResult, error)
- func (z *Zencached) Shutdown()
- func (z *Zencached) Version(ctx context.Context, routerHash []byte) (*OperationResult, error)
- type ZencachedMetricsCollector
Constants ¶
This section is empty.
Variables ¶
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
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
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
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
func ErrorTypeString ¶ added in v1.3.0
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
IsAErrorType returns "true" if the value is listed in the enum definition. "false" otherwise
func (ErrorType) MarshalJSON ¶ added in v1.3.0
MarshalJSON implements the json.Marshaler interface for ErrorType
func (ErrorType) MarshalText ¶ added in v1.3.0
MarshalText implements the encoding.TextMarshaler interface for ErrorType
func (*ErrorType) UnmarshalJSON ¶ added in v1.3.0
UnmarshalJSON implements the json.Unmarshaler interface for ErrorType
func (*ErrorType) UnmarshalText ¶ added in v1.3.0
UnmarshalText implements the encoding.TextUnmarshaler interface for ErrorType
type GetNodeList ¶ added in v1.1.0
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
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
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) GetNodeHost ¶ added in v1.3.0
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
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
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) )
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 (*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 ¶
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
GetConnectedNodes - returns the currently connected nodes
func (*Zencached) GetNodeWorkersByIndex ¶ added in v1.3.0
GetNodeWorkersByIndex - returns a telnet connection by node index
func (*Zencached) Rebalance ¶ added in v1.1.0
func (z *Zencached) Rebalance()
Rebalance - rebalance all nodes
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