redis

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package redis caches bytes using native Redis expiration. It borrows an existing client from pkg/redis and supports standalone, Sentinel and Cluster clients.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Namespace        string        // default default; keys use cache:<namespace>:<key>
	MaxEntryBytes    int           // key + value bytes on Set; default 1 MiB
	OperationTimeout time.Duration // default 5 seconds
}

func (Config) Validate

func (c Config) Validate() error

Validate checks settings without I/O. Zero fields use the documented defaults.

type Store

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

Store is safe for concurrent use. The caller owns the client and closes it after all users stop. Configure context-aware I/O using pkg/redis.Open or OpenURL.

func New

func New(client redis.UniversalClient, cfg Config) (*Store, error)

func (*Store) Clear

func (s *Store) Clear(ctx context.Context) error

Clear scans only this namespace and unlinks keys in batches. It never flushes the database. All cluster primaries are scanned. Concurrent writes/topology changes may survive; quiesce writers for a complete clear. Errors can leave partial progress. The operation has one deadline for the entire traversal.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, key string) error

func (*Store) Exists

func (s *Store) Exists(ctx context.Context, key string) (bool, error)

func (*Store) Get

func (s *Store) Get(ctx context.Context, key string) ([]byte, bool, error)

func (*Store) GetMulti

func (s *Store) GetMulti(ctx context.Context, keys []string) (map[string][]byte, error)

func (*Store) Remember

func (s *Store) Remember(ctx context.Context, key string, ttl time.Duration, load func(context.Context) (any, error)) (any, error)

Remember returns a cached JSON value or loads it on a miss. See cache.Remember for validation, error, expiry and concurrent-loading semantics.

func (*Store) Set

func (s *Store) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error

func (*Store) SetMulti

func (s *Store) SetMulti(ctx context.Context, items map[string][]byte, ttl time.Duration) error

Jump to

Keyboard shortcuts

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