cache

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMetricsHook

func NewMetricsHook() redis.Hook

NewMetricsHook returns a redis.Hook that records command latency and errors on the prometheus default registry. Exported so other Redis clients in the binary (e.g. the DEK cache client constructed in internal/app) can attach the same hook for consistent dashboard data.

Types

type Service

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

Service handles Redis cache operations

func New

func New(cfg *config.Config, log *logger.Logger) (*Service, error)

New creates a new cache service

func (*Service) Delete

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

Delete deletes a value from the cache

func (*Service) DeleteByPrefix

func (s *Service) DeleteByPrefix(ctx context.Context, prefix string) error

DeleteByPrefix deletes all keys matching the given prefix using SCAN + DEL. Uses UNLINK for non-blocking deletion when available (Redis 4.0+).

func (*Service) DeleteSession

func (s *Service) DeleteSession(ctx context.Context, sessionID string) error

DeleteSession deletes a session from the cache

func (*Service) Get

func (s *Service) Get(ctx context.Context, key string) (string, error)

Get gets a value from the cache

func (*Service) GetClient

func (s *Service) GetClient() *redis.Client

GetClient returns the underlying Redis client so other services can reuse the same connection pool instead of opening a duplicate client to the same Redis instance (e.g. the rate limiter). The client remains owned by the cache service and is closed when the cache service stops; callers must not close it themselves.

func (*Service) GetObject

func (s *Service) GetObject(ctx context.Context, key string, value interface{}) error

GetObject gets an object from the cache and unmarshals it into the provided value

func (*Service) GetSession

func (s *Service) GetSession(ctx context.Context, sessionID string) (*types.CachedSession, error)

GetSession retrieves a typed session from the cache. Returns nil, nil when the key does not exist.

func (*Service) Ping

func (s *Service) Ping(ctx context.Context) error

Ping checks the Redis connection

func (*Service) Set

func (s *Service) Set(ctx context.Context, key string, value string, expiration time.Duration) error

Set sets a value in the cache

func (*Service) SetNX

func (s *Service) SetNX(ctx context.Context, key string, value string, expiration time.Duration) (bool, error)

SetNX atomically sets a key only if it does not already exist. Returns true if the key was set, false if it already existed.

func (*Service) SetObject

func (s *Service) SetObject(ctx context.Context, key string, value interface{}, expiration time.Duration) error

SetObject sets an object in the cache

func (*Service) SetSession

func (s *Service) SetSession(ctx context.Context, sessionID string, session types.CachedSession, expiration time.Duration) error

SetSession stores a typed session in the cache.

func (*Service) Start

func (s *Service) Start() error

Start starts the cache service

func (*Service) Stop

func (s *Service) Stop() error

Stop stops the cache service

Jump to

Keyboard shortcuts

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