valkey

package
v0.6.80 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package valkey is a Valkey (Redis protocol) connection as a dependency: a configuration section, a client instrumented with the service's OpenTelemetry providers (command spans only under an operation), a PING probe and a close.

type Config struct {
    config.Backplane `json:"backplane"`
    Cache valkey.Config `json:"cache"` // GREETER_CACHE_ADDR, ...
}

cache := deps.NewDependency(root, valkey.New(cfg.Cache), deps.Name("cache"))
err := cache.Get().Do(ctx, cache.Get().B().Set().Key("k").Value("v").Build()).Error()

The address is one node or a comma-separated list of seeds: a cluster is discovered from whichever answers, a standalone server is used as is.

NewAside is the same connection as a valkeyaside cache-aside client (client-side caching with server invalidation): AsideClient.

Index

Constants

This section is empty.

Variables

View Source
var ErrClusterDB = errors.New("valkey: a cluster has only database 0 unless it is Valkey 9+ with cluster-databases")

ErrClusterDB: a database other than 0 on a cluster without numbered databases.

View Source
var ErrNoAddr = errors.New("valkey: addr is required")

ErrNoAddr: the section has no address.

Functions

func New

func New(cfg Config) deps.Provider[Client]

New is the provider of the client: Provide connects and pings, the probe pings, Close closes.

func NewAside added in v0.6.19

func NewAside(cfg Config, opts ...AsideOption) deps.Provider[AsideClient]

NewAside is the provider of a cache-aside client on the same section as New: TLS, auth and database alike, the connection instrumented with the service's OpenTelemetry providers; Provide connects and pings, the probe pings, Close closes.

owners := deps.NewDependency(root, valkey.NewAside(cfg.Cache), deps.Name("owners"))
owner, err := owners.Get().Get(ctx, time.Minute, "owner:"+id, load)

Types

type AsideClient added in v0.6.19

type AsideClient = valkeyaside.CacheAsideClient

AsideClient is valkeyaside's cache-aside client over client-side caching: Get(ctx, ttl, key, fn) reads a key, filling it once with fn across every client on a miss, and keeps it in this process until the server invalidates it. Client() is the instrumented connection underneath.

type AsideOption added in v0.6.19

type AsideOption func(*valkeyaside.ClientOption)

AsideOption tunes NewAside.

func AsideClientTTL added in v0.6.19

func AsideClientTTL(d time.Duration) AsideOption

AsideClientTTL is how long this client's liveness marker lives (refreshed every half): other clients wait no longer for a fill it abandoned. Default 10s.

func AsideLuaLock added in v0.6.19

func AsideLuaLock() AsideOption

AsideLuaLock takes fill locks with Lua scripts (valkeyaside's UseLuaLock).

type Client

type Client = valkeygo.Client

Client is valkey-go's client: commands are built with B() and sent with Do, DoMulti or DoCache.

type Config

type Config struct {
	// Addr is host:port of a node, or comma-separated seeds of a cluster
	// (host:port,host:port): any one answering is enough to discover it.
	Addr     string        `desc:"host:port of a node, or comma-separated seeds of a cluster." json:"addr,omitempty"`
	Username string        `desc:"ACL user."                                                   json:"username,omitempty"`
	Password config.Secret `desc:"Password."                                                   json:"password,omitempty"`
	// DB is the logical database. How many there are is the server's to
	// say: databases on a standalone server (16 by default),
	// cluster-databases on a Valkey 9+ cluster (1 by default); a classic
	// cluster has only database 0. A number the server does not have fails
	// the connection.
	DB  int64      `desc:"Logical database; a number the server does not have fails the connection." json:"db"  schemapb:"default=0;gte=0"`
	TLS config.TLS `desc:"TLS of the connection."                                                    json:"tls"`
}

Config is the connection's section.

func (Config) Enabled

func (c Config) Enabled() bool

Enabled reports whether an address is set.

func (Config) Validate

func (c Config) Validate() error

Validate checks what the schema cannot: the address is set and the TLS material parses.

Jump to

Keyboard shortcuts

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