valkeyclient

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package valkeyclient provides a lightweight Valkey/Redis RESP protocol client for health checking and replication monitoring.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a minimal Valkey/Redis client using raw RESP protocol. It does not depend on any external Redis Go client library.

func New

func New(addr string) *Client

New creates a new Valkey client for the given address (host:port).

func NewTLS added in v1.0.1

func NewTLS(addr string, tlsConfig *tls.Config) *Client

NewTLS creates a new Valkey client that connects using TLS. The tlsConfig must contain at least the CA certificate for server verification.

func NewTLSWithPassword added in v1.1.0

func NewTLSWithPassword(addr string, tlsConfig *tls.Config, password string) *Client

NewTLSWithPassword creates a TLS Valkey client with password authentication.

func NewWithPassword added in v1.1.0

func NewWithPassword(addr, password string) *Client

NewWithPassword creates a new Valkey client with password authentication. The AUTH command is sent automatically on each connection.

func (*Client) DBSize

func (c *Client) DBSize() (int, error)

DBSize sends the DBSIZE command and returns the number of keys in the current database.

func (*Client) InfoReplication

func (c *Client) InfoReplication() (*ReplicationInfo, error)

InfoReplication sends INFO replication and parses the result.

func (*Client) Ping

func (c *Client) Ping() error

Ping sends a PING command and returns nil if the response is PONG.

func (*Client) ReplicaOf added in v1.1.0

func (c *Client) ReplicaOf(host, port string) error

ReplicaOf sends REPLICAOF <host> <port> to reconfigure a node as a replica of the given master. This is used to fix cascaded replication chains where a replica points to an intermediate node instead of the actual master.

func (*Client) SentinelFailover

func (c *Client) SentinelFailover(name string) error

SentinelFailover sends SENTINEL FAILOVER <name> to trigger a manual failover.

func (*Client) SentinelMaster

func (c *Client) SentinelMaster(name string) (*SentinelMasterInfo, error)

SentinelMaster sends SENTINEL MASTER <name> and parses the result.

func (*Client) SentinelMonitorAdd

func (c *Client) SentinelMonitorAdd(name, ip string, port, quorum int) error

SentinelMonitorAdd sends SENTINEL MONITOR <name> <ip> <port> <quorum> to add a new master to sentinel monitoring.

func (*Client) SentinelRemove

func (c *Client) SentinelRemove(name string) error

SentinelRemove sends SENTINEL REMOVE <name> to remove a monitored master and all its associated replicas and sentinels from sentinel's tracking.

func (*Client) SentinelReset

func (c *Client) SentinelReset(pattern string) error

SentinelReset sends SENTINEL RESET <pattern> to reset all matching masters. This clears the sentinel's internal failover cooldown state, allowing a new failover to be triggered immediately. The pattern "*" matches all masters.

func (*Client) SentinelSet

func (c *Client) SentinelSet(name, option, value string) error

SentinelSet sends SENTINEL SET <name> <option> <value> to change a sentinel configuration parameter for a monitored master.

func (*Client) Wait

func (c *Client) Wait(numReplicas int, timeoutMs int) (int, error)

Wait sends the WAIT command to block until all the previous write commands are acknowledged by at least numReplicas replicas, or until the timeout (in milliseconds) expires. It returns the number of replicas that acknowledged.

type ConnectionError added in v1.1.2

type ConnectionError struct {
	// Addr is the host:port that was dialled.
	Addr string
	// Cause is the underlying network error.
	Cause error
	// Hint is a short, human-readable explanation of the probable cause and
	// how to resolve it (e.g. "check firewall rules").
	Hint string
}

ConnectionError is returned whenever a TCP connection to a Valkey or Sentinel instance cannot be established. It always carries the target address and an actionable hint so that administrators can quickly identify firewall rules or NetworkPolicy misconfigurations that block access.

func (*ConnectionError) Error added in v1.1.2

func (e *ConnectionError) Error() string

func (*ConnectionError) Unwrap added in v1.1.2

func (e *ConnectionError) Unwrap() error

Unwrap preserves the full error chain so errors.Is / errors.As still work.

type ReplicationInfo

type ReplicationInfo struct {
	Role                 string
	ConnectedSlaves      int
	MasterHost           string
	MasterPort           string
	MasterLinkStatus     string
	MasterSyncInProgress bool
}

ReplicationInfo holds parsed INFO replication output.

type SentinelMasterInfo

type SentinelMasterInfo struct {
	Name      string
	IP        string
	Port      string
	NumSlaves int
	Quorum    int
	Flags     string
}

SentinelMasterInfo holds parsed SENTINEL MASTER output.

Jump to

Keyboard shortcuts

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