cache

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2025 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package cache provides tools for caching data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommonProvider

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

func New

func New(opts ...Option) (*CommonProvider, error)

func (*CommonProvider) Close

func (p *CommonProvider) Close() error

Close closes connection to cache.

func (*CommonProvider) Decr

func (p *CommonProvider) Decr(ctx context.Context, key string) (int64, error)

Decr decrements key.

func (*CommonProvider) DecrBy

func (p *CommonProvider) DecrBy(ctx context.Context, key string, decrement int64) (int64, error)

DecrBy decrements key by value (numeric such as -1, -2 and so on).

func (*CommonProvider) Del

func (p *CommonProvider) Del(ctx context.Context, keys ...string) error

Del deletes keys.

func (*CommonProvider) DelByPattern added in v1.11.1

func (p *CommonProvider) DelByPattern(ctx context.Context, pattern string, batchSize *int64) error

DelByPattern deletes all keys, which matches provided pattern.

func (*CommonProvider) Get

func (p *CommonProvider) Get(ctx context.Context, key string) (string, error)

Get gets key.

func (*CommonProvider) GetDel

func (p *CommonProvider) GetDel(ctx context.Context, key string) (string, error)

GetDel gets key and deletes it.

func (*CommonProvider) GetEx

func (p *CommonProvider) GetEx(ctx context.Context, key string, expiration time.Duration) (string, error)

GetEx gets key and expires it, if ttl is expired.

func (*CommonProvider) Incr

func (p *CommonProvider) Incr(ctx context.Context, key string) (int64, error)

Incr increments key.

func (*CommonProvider) IncrBy

func (p *CommonProvider) IncrBy(ctx context.Context, key string, value int64) (int64, error)

IncrBy increments key by value (numeric such as +1, +2 and so on).

func (*CommonProvider) Ping

func (p *CommonProvider) Ping(ctx context.Context) (string, error)

Ping checks status.

func (*CommonProvider) Set

func (p *CommonProvider) Set(ctx context.Context, key string, value any, expiration time.Duration) error

Set sets key.

func (*CommonProvider) SetNX

func (p *CommonProvider) SetNX(ctx context.Context, key string, value any, expiration time.Duration) error

SetNX sets key, if not already exists.

type Option

type Option func(options *options) error

Option represents golang functional option pattern func for configuration.

func WithClientName

func WithClientName(clientName string) Option

func WithConnectionMaxIdleTime

func WithConnectionMaxIdleTime(connectionMaxIdleTime time.Duration) Option

func WithConnectionMaxLifetime

func WithConnectionMaxLifetime(connectionMaxLifetime time.Duration) Option

func WithContextTimeoutEnabled

func WithContextTimeoutEnabled(contextTimeoutEnabled bool) Option

func WithDB

func WithDB(db int) Option

func WithDialTimeout

func WithDialTimeout(dialTimeout time.Duration) Option

func WithHost

func WithHost(host string) Option

func WithMaxActiveConnections

func WithMaxActiveConnections(maxActiveConnections int) Option

func WithMaxIdleConnections

func WithMaxIdleConnections(maxIdleConnections int) Option

func WithMaxRetries

func WithMaxRetries(maxRetries int) Option

func WithMaxRetryBackoff

func WithMaxRetryBackoff(maxRetryBackoff time.Duration) Option

func WithMinIdleConnections

func WithMinIdleConnections(minIdleConnections int) Option

func WithMinRetryBackoff

func WithMinRetryBackoff(minRetryBackoff time.Duration) Option

func WithPassword

func WithPassword(password string) Option

func WithPoolFIFO

func WithPoolFIFO(poolFIFO bool) Option

func WithPoolSize

func WithPoolSize(poolSize int) Option

func WithPoolTimeout

func WithPoolTimeout(poolTimeout time.Duration) Option

func WithPort

func WithPort(port int) Option

func WithReadTimeout

func WithReadTimeout(readTimeout time.Duration) Option

func WithUsername

func WithUsername(username string) Option

func WithWriteTimeout

func WithWriteTimeout(writeTimeout time.Duration) Option

type Provider

type Provider interface {
	// Set sets key.
	Set(ctx context.Context, key string, value any, expiration time.Duration) error

	// SetNX sets key, if not already exists.
	SetNX(ctx context.Context, key string, value any, expiration time.Duration) error

	// Get gets key.
	Get(ctx context.Context, key string) (string, error)

	// GetEx gets key and expires it, if ttl is expired.
	GetEx(ctx context.Context, key string, expiration time.Duration) (string, error)

	// GetDel gets key and deletes it.
	GetDel(ctx context.Context, key string) (string, error)

	// Incr increments key.
	Incr(ctx context.Context, key string) (int64, error)

	// IncrBy increments key by value (numeric such as +1, +2 and so on).
	IncrBy(ctx context.Context, key string, value int64) (int64, error)

	// Decr decrements key.
	Decr(ctx context.Context, key string) (int64, error)

	// DecrBy decrements key by value (numeric such as -1, -2 and so on).
	DecrBy(ctx context.Context, key string, decrement int64) (int64, error)

	// Del deletes key.
	Del(ctx context.Context, keys ...string) error

	// DelByPattern deletes all keys, which matches provided pattern.
	DelByPattern(ctx context.Context, pattern string, batchSize *int64) error

	// Ping checks status.
	Ping(ctx context.Context) (string, error)

	Close() error
}

Provider provides methods for setting cache and getting cached data.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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