redis

package module
v2.0.0-...-1948240 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

func NewCache

func NewCache(opts ...Option) *Cache

NewCache returns a new Redis-backed Cache. The optional opts override the default configuration.

func (*Cache) AddPrefix

func (c *Cache) AddPrefix(key string) string

AddPrefix returns key prefixed with the cache's key prefix.

func (*Cache) Client

func (c *Cache) Client() any

Client returns the underlying Redis client.

func (*Cache) Close

func (c *Cache) Close() error

Close closes the cache. It reports errors.ErrCacheClosed when the cache is already closed. The built-in client is closed only when it was created by NewCache.

func (*Cache) DecrFloat

func (c *Cache) DecrFloat(ctx context.Context, key string, value float64) (float64, error)

DecrFloat decrements the float stored at key by value and returns the resulting value.

func (*Cache) DecrInt

func (c *Cache) DecrInt(ctx context.Context, key string, value int64) (int64, error)

DecrInt decrements the integer stored at key by value and returns the resulting value.

func (*Cache) Delete

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

Delete removes the given keys and reports how many keys were actually deleted.

func (*Cache) Get

func (c *Cache) Get(ctx context.Context, key string, def ...any) cache.Result

Get returns the value of key. The optional def is returned when the entry does not exist.

func (*Cache) GetSet

func (c *Cache) GetSet(ctx context.Context, key string, fn cache.SetValueFunc) cache.Result

GetSet returns the value of key, generating it with fn and storing it when the entry does not exist.

func (*Cache) Has

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

Has reports whether the entry identified by key exists.

func (*Cache) IncrFloat

func (c *Cache) IncrFloat(ctx context.Context, key string, value float64) (float64, error)

IncrFloat increments the float stored at key by value and returns the resulting value.

func (*Cache) IncrInt

func (c *Cache) IncrInt(ctx context.Context, key string, value int64) (int64, error)

IncrInt increments the integer stored at key by value and returns the resulting value.

func (*Cache) Set

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

Set stores value under key. The optional expiration controls the entry's time to live: when it is omitted a random duration within the configured expiration range is used, a value greater than 0 sets an explicit expiration, -1 keeps the existing expiration and a value less than -1 makes the entry never expire.

type Option

type Option func(o *options)

func WithAddrs

func WithAddrs(addrs ...string) Option

WithAddrs sets the connection addresses. It accepts one or more Redis node addresses.

func WithClient

func WithClient(client redis.UniversalClient) Option

WithClient sets an external client. The external client takes precedence over the built-in one.

func WithCredentials

func WithCredentials(certFile, keyFile, caFile string) Option

WithCredentials sets the client certificate, the client private key and the CA certificate. Each argument is a file path.

func WithDB

func WithDB(db int) Option

WithDB sets the database number.

func WithMaxExpiration

func WithMaxExpiration(maxExpiration time.Duration) Option

WithMaxExpiration sets the maximum expiration time. Non-positive values are ignored.

func WithMaxRetries

func WithMaxRetries(maxRetries int) Option

WithMaxRetries sets the maximum number of retries.

func WithMinExpiration

func WithMinExpiration(minExpiration time.Duration) Option

WithMinExpiration sets the minimum expiration time. Non-positive values are ignored.

func WithNilExpiration

func WithNilExpiration(nilExpiration time.Duration) Option

WithNilExpiration sets the expiration time of a cached nil. Non-positive values are ignored.

func WithNilValue

func WithNilValue(nilValue string) Option

WithNilValue sets the placeholder value that marks a cached nil.

func WithPassword

func WithPassword(password string) Option

WithPassword sets the password used for authentication.

func WithPrefix

func WithPrefix(prefix string) Option

WithPrefix sets the key prefix.

func WithUsername

func WithUsername(username string) Option

WithUsername sets the username used for authentication.

Jump to

Keyboard shortcuts

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