cache

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package cache provides Redis caching functionality for the application. It includes connection management, basic operations, and caching utilities.

Index

Constants

View Source
const (
	DefaultTTL = 30 * time.Minute
	MaxRetries = 3
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache wraps the Redis client and provides caching operations

func NewCache

func NewCache(cfg *RedisConfig, logger *logger.Logger) (*Cache, error)

NewCache initializes a new Redis cache connection

func (*Cache) Close

func (c *Cache) Close() error

Close gracefully closes the Redis connection

func (*Cache) Delete

func (c *Cache) Delete(ctx context.Context, key string) error

Delete removes a key from Redis

func (*Cache) DeletePattern

func (c *Cache) DeletePattern(ctx context.Context, pattern string) error

DeletePattern removes all keys matching a pattern

func (*Cache) Exists

func (c *Cache) Exists(ctx context.Context, key string) (bool, error)

Exists checks if a key exists in Redis

func (*Cache) FlushDB

func (c *Cache) FlushDB(ctx context.Context) error

FlushDB clears all keys in the current database

func (*Cache) Get

func (c *Cache) Get(ctx context.Context, key string, dest any) error

Get retrieves a value from Redis by key

func (*Cache) GetClient

func (c *Cache) GetClient() *redis.Client

GetClient returns the underlying Redis client for advanced operations

func (*Cache) Set

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

Set stores a key-value pair in Redis with optional TTL

func (*Cache) TTL

func (c *Cache) TTL(ctx context.Context, key string) (time.Duration, error)

TTL gets the remaining time to live for a key

type RedisConfig

type RedisConfig struct {
	Host     string
	Port     string
	Password string
	DB       int
}

RedisConfig holds Redis connection configuration

Jump to

Keyboard shortcuts

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