valkey

package
v0.6.89 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 15 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

View Source
const (
	DefaultDialTimeout      = 5 * time.Second
	DefaultConnWriteTimeout = 10 * time.Second
	DefaultBlockingPoolSize = 1024
	DefaultBlockingPipeline = 2000
	DefaultBufferEachConn   = 1 << 19
)

Defaults of the section: explicit, never derived from the node. A zero field of a Config built by hand reads its default too.

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"`
	// DialTimeout bounds establishing one connection.
	DialTimeout time.Duration `desc:"Bound of establishing one connection." json:"dial_timeout" schemapb:"default=5s;gt=0"`
	// ConnWriteTimeout is the per-connection deadline of writing a command
	// and waiting for its pipelined reply (valkey-go has no separate read
	// timeout).
	ConnWriteTimeout time.Duration `desc:"Deadline of a command's write and its pipelined reply." json:"conn_write_timeout" schemapb:"default=10s;gt=0"`
	ConnLifetime     time.Duration `desc:"A connection this old is replaced; 0: for ever."        json:"conn_lifetime"      schemapb:"default=0s;gte=0"`
	// Blocking pool: dedicated connections of blocking commands (BLPOP,
	// XREAD BLOCK, ...) and of transactions.
	BlockingPoolSize    int64         `` /* 127-byte string literal not displayed */
	BlockingPoolMinSize int64         `desc:"Dedicated connections kept open."                              json:"blocking_pool_min_size" schemapb:"default=0;gte=0"`
	BlockingPoolCleanup time.Duration `` /* 126-byte string literal not displayed */
	// Pipelining of the shared connections.
	PipelineMultiplex     int64         `` /* 149-byte string literal not displayed */
	BlockingPipeline      int64         `` /* 145-byte string literal not displayed */
	MaxFlushDelay         time.Duration `` /* 144-byte string literal not displayed */
	DisableAutoPipelining bool          `` /* 141-byte string literal not displayed */
	ReadBufferEachConn    int64         `` /* 147-byte string literal not displayed */
	WriteBufferEachConn   int64         `` /* 147-byte string literal not displayed */
}

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