cache

package
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: MIT Imports: 8 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheInstance

type CacheInstance struct {
	Client *redis.Client
}

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

func (c *CacheInstance) Do(ctx context.Context, args ...any) *redis.Cmd

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.

func (*CacheInstance) Get added in v0.5.1

func (c *CacheInstance) Get(ctx context.Context, key string) ([]byte, error)

Get returns the value stored at key.

func (*CacheInstance) Ping added in v0.5.1

func (c *CacheInstance) Ping(ctx context.Context) error

Ping checks connectivity to the cache server.

func (*CacheInstance) Set added in v0.5.1

func (c *CacheInstance) Set(ctx context.Context, key string, value any, expiration time.Duration) error

Set stores value at key with the given expiration (0 for no expiration).

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 NewHook

func NewHook(prefix string) *Hook

New returns a Hook that namespaces every key under prefix + ":".

func (*Hook) DialHook

func (h *Hook) DialHook(next redis.DialHook) redis.DialHook

implementations of redis.Hook interfaces to insert key prefix

func (*Hook) ProcessHook

func (h *Hook) ProcessHook(next redis.ProcessHook) redis.ProcessHook

func (*Hook) ProcessPipelineHook

func (h *Hook) ProcessPipelineHook(next redis.ProcessPipelineHook) redis.ProcessPipelineHook

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL