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 ¶
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.
var ErrNoAddr = errors.New("valkey: addr is required")
ErrNoAddr: the section has no address.
Functions ¶
func New ¶
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 ¶
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.