cache

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCacheMiss = errors.New("cache miss")

Functions

func GetJSON

func GetJSON[T any](ctx context.Context, rdb redis.UniversalClient, key string) (T, error)

func Key

func Key(parts ...string) string

func RememberJSON

func RememberJSON[T any](ctx context.Context, rdb redis.UniversalClient, key string, ttl time.Duration, load func(context.Context) (T, error)) (T, error)

func SetJSON

func SetJSON(ctx context.Context, rdb redis.UniversalClient, key string, value any, ttl time.Duration) error

Types

type Client

type Client interface{ redis.UniversalClient }

type Lock

type Lock struct {
	// contains filtered or unexported fields
}

func LockWithWait

func LockWithWait(ctx context.Context, client redis.UniversalClient, key string, ttl, wait, interval time.Duration) (*Lock, error)

func TryLock

func TryLock(ctx context.Context, client redis.UniversalClient, key string, ttl time.Duration) (*Lock, bool, error)

func (*Lock) Key

func (l *Lock) Key() string

func (*Lock) Refresh

func (l *Lock) Refresh(ctx context.Context, ttl time.Duration) (bool, error)

func (*Lock) Token

func (l *Lock) Token() string

func (*Lock) Unlock

func (l *Lock) Unlock(ctx context.Context) error

type Option

type Option func(*options)

func WithLogger

func WithLogger(l *slog.Logger) Option

func WithMetrics

func WithMetrics(m *metrics.Metrics) Option

type Redis

type Redis struct {
	Client redis.UniversalClient
	// contains filtered or unexported fields
}

func NewRedis

func NewRedis(ctx context.Context, cfg RedisConfig, opts ...Option) (*Redis, error)

func (*Redis) Close

func (r *Redis) Close() error

func (*Redis) Ping

func (r *Redis) Ping(ctx context.Context) error

type RedisConfig

type RedisConfig struct {
	Mode         string   `json:"mode" yaml:"mode"`
	Addr         string   `json:"addr" yaml:"addr"`
	Addrs        []string `json:"addrs" yaml:"addrs"`
	Username     string   `json:"username" yaml:"username"`
	Password     string   `json:"password" yaml:"password"`
	DB           int      `json:"db" yaml:"db"`
	DialTimeout  string   `json:"dial_timeout" yaml:"dial_timeout"`
	ReadTimeout  string   `json:"read_timeout" yaml:"read_timeout"`
	WriteTimeout string   `json:"write_timeout" yaml:"write_timeout"`
	PoolSize     int      `json:"pool_size" yaml:"pool_size"`
}

Jump to

Keyboard shortcuts

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