Documentation
¶
Overview ¶
Package cache provides a redis.Hook that transparently prefixes every key with a fixed namespace (e.g. "myapp:") so callers never need to build the prefixed key themselves.
Index ¶
- type CacheInstance
- func (c *CacheInstance) Close() error
- func (c *CacheInstance) Do(ctx context.Context, args ...any) *redis.Cmd
- func (c *CacheInstance) Get(ctx context.Context, key string) ([]byte, error)
- func (c *CacheInstance) Ping(ctx context.Context) error
- func (c *CacheInstance) Set(ctx context.Context, key string, value any, expiration time.Duration) error
- type Hook
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheInstance ¶
func Init ¶
func Init() (*CacheInstance, error)
Init creates a cache client using the provided config. Uses the go-redis driver, which speaks the Redis protocol and is compatible with Redis and Valkey servers alike. Retries cfg.RetryCount times before giving up; exhausting retries is fatal.
func (*CacheInstance) Close ¶
func (c *CacheInstance) Close() error
func (*CacheInstance) Do ¶ added in v0.5.1
Do executes an arbitrary cache command, e.g. Do(ctx, "expire", "key", 60). Use this for commands not covered by Get/Set until a dedicated method exists.
type Hook ¶
type Hook struct {
// contains filtered or unexported fields
}
Hook prefixes cache keys with Prefix + ":" for every command it recognizes. Unrecognized commands (SCAN, PING, INFO, etc.) pass through untouched.
func (*Hook) ProcessHook ¶
func (h *Hook) ProcessHook(next redis.ProcessHook) redis.ProcessHook
func (*Hook) ProcessPipelineHook ¶
func (h *Hook) ProcessPipelineHook(next redis.ProcessPipelineHook) redis.ProcessPipelineHook