Documentation
¶
Overview ¶
Package redis is a cache.Store on Redis or Valkey, in its own Go module so the go-redis client never reaches a project that does not import it.
New connects, verifies the connection with a PING and owns the client it creates; Close closes it. NewFromClient wraps a client you already have (Cluster, Sentinel, a Unix socket, dynamic credentials): it does not ping and does not own the client, so its Close does nothing and you remain responsible for closing the client you supplied.
Every command receives the caller's context. A Redis server that refuses a value for its size is reported as cache.ErrTooLarge; every other server or network error is returned wrapped, never hidden. Support is claimed only for the Redis and Valkey versions the module's CI runs.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// URL is required: redis://[user:password@]host:port[/db] or rediss://
// for TLS. The database number is the URL path (redis://host:6379/3);
// there is no separate field for it.
URL string
// Username and Password, when not empty, override the URL's userinfo.
Username string
Password string
// TLSConfig customises TLS. It requires a rediss:// URL: a TLSConfig
// with redis:// is rejected rather than silently changing transport
// security.
TLSConfig *tls.Config
// DialTimeout, ReadTimeout and WriteTimeout, when positive, override the
// client's defaults.
DialTimeout time.Duration
ReadTimeout time.Duration
WriteTimeout time.Duration
// PoolSize, when positive, is the most connections the client keeps.
PoolSize int
}
Config describes the server New connects to.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a Redis- or Valkey-backed cache.Store.
func New ¶
New connects to the server cfg describes and verifies it with a PING under ctx. It fails fast on a bad URL, bad credentials or an unreachable server; the returned error is ordinary, so an application may choose to start without its cache. If the PING fails, the client New created is closed, so a failed New leaks no connection. The Store owns its client: Close closes it.
func NewFromClient ¶
func NewFromClient(client goredis.UniversalClient) *Store
NewFromClient wraps a client you built, for Cluster, Sentinel, Unix sockets, dynamic credentials and other deployment shapes.
OWNERSHIP: NewFromClient does not ping, and the returned Store does not own client. Its Close is intentionally a no-op; you remain responsible for closing the client you supplied, when you are done with it.
func (*Store) Close ¶
Close closes the client a Store created with New. For a Store made by NewFromClient it does nothing: the host closes its own client.