Documentation
¶
Index ¶
- Variables
- func IsCacheError(err error) bool
- func IsConnectionError(err error) bool
- func IsKeyNotFoundError(err error) bool
- func IsRetryableError(err error) bool
- func IsTimeoutError(err error) bool
- func WrapGRPCError(err error, operation string) error
- func WrapTCPError(err error, operation string) error
- type CacheError
- type Client
- func (c *Client) BatchGet(keys []string) (map[string][]byte, error)
- func (c *Client) BatchSet(items map[string][]byte, ttlSeconds *uint64) error
- func (c *Client) Close() error
- func (c *Client) Delete(key string) (bool, error)
- func (c *Client) Get(key string) ([]byte, error)
- func (c *Client) GetConfig() ClientConfig
- func (c *Client) GetWithMetadata(key string) ([]byte, *pb.EntryMetadata, error)
- func (c *Client) Health() (*pb.HealthResponse, error)
- func (c *Client) IsConnected() bool
- func (c *Client) Metrics() (string, error)
- func (c *Client) Set(key string, value []byte, ttlSeconds *uint64) error
- type ClientConfig
- type ErrorCode
- type ErrorReporter
- type TCPClient
- func (c *TCPClient) Close() error
- func (c *TCPClient) Delete(key string) (bool, error)
- func (c *TCPClient) Get(key string) (string, error)
- func (c *TCPClient) GetConfig() TCPClientConfig
- func (c *TCPClient) IsConnected() bool
- func (c *TCPClient) Ping() error
- func (c *TCPClient) Set(key, value string) error
- type TCPClientConfig
Constants ¶
This section is empty.
Variables ¶
var ( ErrClientClosed = errors.New("client is closed") ErrInvalidKey = errors.New("key cannot be empty") ErrInvalidValue = errors.New("value cannot be nil") ErrConnectionFailed = errors.New("connection failed") ErrTimeout = errors.New("operation timed out") ErrServerError = errors.New("server error") ErrInvalidConfig = errors.New("invalid configuration") ErrKeyNotFound = errors.New("key not found") ErrOperationFailed = errors.New("operation failed") )
Error types
Functions ¶
func IsConnectionError ¶
Checks if an error is related to connection issues
func IsKeyNotFoundError ¶
Checks if an error indicates a key was not found
func IsRetryableError ¶
Checks if an error should trigger a retry
func WrapGRPCError ¶
Converts a gRPC error to a CacheError
func WrapTCPError ¶
Converts a TCP error to a CacheError
Types ¶
type CacheError ¶
type CacheError struct {
Code ErrorCode `json:"code"`
Message string `json:"message"`
Operation string `json:"operation"`
Key string `json:"key,omitempty"`
Cause error `json:"cause,omitempty"`
Retryable bool `json:"retryable"`
}
func GetCacheError ¶
func GetCacheError(err error) *CacheError
Extracts a CacheError from an error chain
func NewCacheError ¶
func NewCacheError(code ErrorCode, message, operation string) *CacheError
Creates a new CacheError
func NewCacheErrorWithCause ¶
func NewCacheErrorWithCause(code ErrorCode, message, operation string, cause error) *CacheError
Creates a new CacheError with an underlying cause
func NewCacheErrorWithKey ¶
func NewCacheErrorWithKey(code ErrorCode, message, operation, key string) *CacheError
Creates a new CacheError with a key
func (*CacheError) IsRetryable ¶
func (e *CacheError) IsRetryable() bool
Returns whether this error should trigger a retry
func (*CacheError) IsTemporary ¶
func (e *CacheError) IsTemporary() bool
Returns whether this is a temporary error
func (*CacheError) Unwrap ¶
func (e *CacheError) Unwrap() error
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Subzero Client
func NewClient ¶
func NewClient(config *ClientConfig) (*Client, error)
func (*Client) GetConfig ¶
func (c *Client) GetConfig() ClientConfig
GetConfig returns a copy of the client configuration
func (*Client) GetWithMetadata ¶
GetWithMetadata retrieves a value and its metadata by key
func (*Client) Health ¶
func (c *Client) Health() (*pb.HealthResponse, error)
Health checks the health of the cache server
func (*Client) IsConnected ¶
IsConnected checks if the client has active connections
type ClientConfig ¶
type ClientConfig struct {
// Connection settings
Address string `json:"address"`
MaxConnections int `json:"max_connections"`
ConnectTimeout time.Duration `json:"connect_timeout"`
RequestTimeout time.Duration `json:"request_timeout"`
KeepAliveTime time.Duration `json:"keep_alive_time"`
KeepAliveTimeout time.Duration `json:"keep_alive_timeout"`
// Retry settings
MaxRetries int `json:"max_retries"`
InitialBackoff time.Duration `json:"initial_backoff"`
MaxBackoff time.Duration `json:"max_backoff"`
BackoffMultiplier float64 `json:"backoff_multiplier"`
// Connection pool settings
EnablePooling bool `json:"enable_pooling"`
PoolReuse bool `json:"pool_reuse"`
// TLS settings
EnableTLS bool `json:"enable_tls"`
TLSServerName string `json:"tls_server_name"`
}
func DefaultConfig ¶
func DefaultConfig() *ClientConfig
func ProductionConfig ¶
func ProductionConfig(address string) *ClientConfig
type ErrorCode ¶
type ErrorCode int
const ( ErrorCodeUnknown ErrorCode = iota ErrorCodeInvalidKey ErrorCodeInvalidValue ErrorCodeInvalidConfig ErrorCodeConnectionFailed ErrorCodeTimeout ErrorCodeServerError ErrorCodeKeyNotFound ErrorCodeOperationFailed ErrorCodeClientClosed ErrorCodeTooManyRetries ErrorCodeResourceExhausted ErrorCodePermissionDenied )
type ErrorReporter ¶
type ErrorReporter struct {
OnError func(err *CacheError)
}
Provides structured error reporting capabilities
func NewErrorReporter ¶
func NewErrorReporter(onError func(err *CacheError)) *ErrorReporter
Creates a new error reporter
func (*ErrorReporter) ReportError ¶
func (r *ErrorReporter) ReportError(err error)
Reports an error if it's a CacheError
type TCPClient ¶
type TCPClient struct {
// contains filtered or unexported fields
}
TCP Protocol Client
func NewTCPClient ¶
func NewTCPClient(config *TCPClientConfig) (*TCPClient, error)
Create new TCP client with given config
func (*TCPClient) GetConfig ¶
func (c *TCPClient) GetConfig() TCPClientConfig
func (*TCPClient) IsConnected ¶
type TCPClientConfig ¶
type TCPClientConfig struct {
Address string `json:"address"`
ConnectTimeout time.Duration `json:"connect_timeout"`
ReadTimeout time.Duration `json:"read_timeout"`
WriteTimeout time.Duration `json:"write_timeout"`
MaxRetries int `json:"max_retries"`
RetryDelay time.Duration `json:"retry_delay"`
KeepAlive bool `json:"keep_alive"`
}
func DefaultTCPConfig ¶
func DefaultTCPConfig() *TCPClientConfig