Documentation
¶
Overview ¶
Package cache provides a Redis/Valkey-backed cache client with OpenTelemetry instrumentation, built on go-redis v9.
It exposes typed methods (SetJSON, GetJSON) for struct values and GetBytes for raw byte access. OpenTelemetry tracing and metrics are enabled by default on every client.
Basic usage:
c, err := cache.New(ctx, "redis://localhost:6379/0")
if err != nil { ... }
defer c.Close()
err = c.SetJSON(ctx, "mykey", myStruct, 15*time.Minute)
found, err := c.GetJSON(ctx, "mykey", &myStruct)
Index ¶
- type Client
- func (c *Client) Close() error
- func (c *Client) GetBytes(ctx context.Context, key string) ([]byte, error)
- func (c *Client) GetJSON(ctx context.Context, key string, dest any) (bool, error)
- func (c *Client) Ping(ctx context.Context) error
- func (c *Client) SetJSON(ctx context.Context, key string, val any, ttl time.Duration) error
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a thin wrapper around a Redis client that supports JSON serialisation.
Zero value is not usable — use New() to construct.
func New ¶
New builds a Client from a Redis URL and applies the given options.
The URL must be in redis:// or rediss:// format as accepted by redis.ParseURL (e.g. "redis://localhost:6379/0"). OpenTelemetry tracing and metrics are automatically enabled on every client.
Callers MUST call Close() when the client is no longer needed.
func (*Client) GetBytes ¶
GetBytes retrieves the raw byte slice stored at key. It returns (nil, nil) when the key does not exist.
func (*Client) GetJSON ¶
GetJSON retrieves the value at key and unmarshals it into dest. It returns (true, nil) on a cache hit, (false, nil) when the key does not exist, and (false, err) on any other error.