cache

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidDelInput = errors.New("invalid input type for Del operation")
	ErrNilClient       = errors.New("redis client is nil")
	ErrEmptyInput      = errors.New("empty input provided")
	ErrNilDB           = errors.New("database connection is nil")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	RedisURL         string
	Password         string
	DB               int
	ConnectTimeout   time.Duration
	OperationTimeout time.Duration
	MaxRetries       int
	MinRetryBackoff  time.Duration
	MaxRetryBackoff  time.Duration
}

Config holds Redis configuration

type OptFunc

type OptFunc func(*Config)

OptFunc defines the signature for an option function

func WithDB

func WithDB(db int) OptFunc

WithDB sets the Redis database number

func WithPassword

func WithPassword(password string) OptFunc

WithPassword sets the Redis password

func WithRedisURL

func WithRedisURL(url string) OptFunc

WithRedisURL sets the Redis URL

type Persistent

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

Persistent contains the persistent Redis and DB connections

func MustConnect

func MustConnect(db *sqlx.DB, opts ...OptFunc) *Persistent

MustConnect creates a new Persistent instance with default options

func NewWithOptions

func NewWithOptions(db *sqlx.DB, cfg *Config) *Persistent

NewWithOptions creates a new Persistent instance with the given options

func (*Persistent) Close

func (p *Persistent) Close() error

func (*Persistent) Del

func (p *Persistent) Del(ctx context.Context, input interface{}) error

func (*Persistent) DelByPattern

func (p *Persistent) DelByPattern(ctx context.Context, pattern string) error

func (*Persistent) Get

func (p *Persistent) Get(ctx context.Context, key string, dest interface{}, query func() error) error

func (*Persistent) GetDB

func (p *Persistent) GetDB() *sqlx.DB

func (*Persistent) GetRedis

func (p *Persistent) GetRedis() *redis.Client

func (*Persistent) Set

func (p *Persistent) Set(ctx context.Context, key string, ttl time.Duration, value interface{}, fn func() error) error

Jump to

Keyboard shortcuts

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