valkey

package
v1.3.12 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package valkey provides a Valkey/Redis client wrapper with health checking and lifecycle management.

This package wraps the go-redis library to provide connection pooling, health checks, and clean shutdown. It supports both standard Redis and Valkey (Redis fork) servers.

Basic usage:

client, err := valkey.New(&valkey.Config{
    Host:     "localhost",
    Port:     6379,
    Database: 0,
})
if err != nil {
    log.Fatal(err)
}
defer client.Close()

val, err := client.Get(ctx, "key").Result()
if err != nil {
    return err
}

For TLS connections, configure the TLS field in Config. The underlying redis.UniversalClient is exposed via the Client field for direct access to all standard Redis operations.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrValkeyPoolNil            = errors.New("valkey: client connection is nil")
	ErrInvalidHost              = errors.New("valkey: host is required")
	ErrInvalidPort              = errors.New("valkey: port must be between 1 and 65535")
	ErrInvalidDB                = errors.New("valkey: database number must be non-negative")
	ErrInvalidPoolSize          = errors.New("valkey: pool size must be positive")
	ErrConfigNil                = errors.New("valkey: configuration must not be nil")
	ErrCAParseFailure           = errors.New("failed to parse CA certificate")
	ErrHealthCheckNoActiveConns = errors.New("valkey health check failed: no active connections in pool")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Host            string
	Port            int
	Password        string
	DB              int
	DialTimeout     time.Duration
	MaxIdleConns    int
	MinIdleConns    int
	PingTimeout     time.Duration
	PoolSize        int
	ReadTimeout     time.Duration
	WriteTimeout    time.Duration
	MaxRetries      int
	MinRetryBackoff time.Duration
	MaxRetryBackoff time.Duration
	TLSEnabled      bool
	TLSSkipVerify   bool
	TLSCertFile     string
	TLSKeyFile      string
	TLSCAFile       string
}

func (*Config) Validate

func (cfg *Config) Validate() error

func (*Config) WithDefaults

func (cfg *Config) WithDefaults() *Config

type Valkey

type Valkey struct {
	*redis.Client
}

func New

func New(cfg *Config) (*Valkey, error)

func (*Valkey) HealthCheck

func (v *Valkey) HealthCheck(ctx context.Context) error

func (*Valkey) Name

func (v *Valkey) Name() string

func (*Valkey) PoolStats

func (v *Valkey) PoolStats() *redis.PoolStats

func (*Valkey) Start

func (v *Valkey) Start(ctx context.Context) error

func (*Valkey) Stop

func (v *Valkey) Stop() error

Jump to

Keyboard shortcuts

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