Documentation
¶
Index ¶
- type Cache
- func (c *Cache) AddPrefix(key string) string
- func (c *Cache) Client() any
- func (c *Cache) Close() error
- func (c *Cache) DecrFloat(ctx context.Context, key string, value float64) (float64, error)
- func (c *Cache) DecrInt(ctx context.Context, key string, value int64) (int64, error)
- func (c *Cache) Delete(ctx context.Context, keys ...string) (int64, error)
- func (c *Cache) Get(ctx context.Context, key string, def ...any) cache.Result
- func (c *Cache) GetSet(ctx context.Context, key string, fn cache.SetValueFunc) cache.Result
- func (c *Cache) Has(ctx context.Context, key string) (bool, error)
- func (c *Cache) IncrFloat(ctx context.Context, key string, value float64) (float64, error)
- func (c *Cache) IncrInt(ctx context.Context, key string, value int64) (int64, error)
- func (c *Cache) Set(ctx context.Context, key string, value any, expiration ...time.Duration) error
- type Option
- func WithAddrs(addrs ...string) Option
- func WithClient(client redis.UniversalClient) Option
- func WithCredentials(certFile, keyFile, caFile string) Option
- func WithDB(db int) Option
- func WithMaxExpiration(maxExpiration time.Duration) Option
- func WithMaxRetries(maxRetries int) Option
- func WithMinExpiration(minExpiration time.Duration) Option
- func WithNilExpiration(nilExpiration time.Duration) Option
- func WithNilValue(nilValue string) Option
- func WithPassword(password string) Option
- func WithPrefix(prefix string) Option
- func WithUsername(username string) Option
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 ¶
NewCache returns a new Redis-backed Cache. The optional opts override the default configuration.
func (*Cache) Close ¶
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 ¶
DecrFloat decrements the float stored at key by value and returns the resulting value.
func (*Cache) DecrInt ¶
DecrInt decrements the integer stored at key by value and returns the resulting value.
func (*Cache) Delete ¶
Delete removes the given keys and reports how many keys were actually deleted.
func (*Cache) Get ¶
Get returns the value of key. The optional def is returned when the entry does not exist.
func (*Cache) GetSet ¶
GetSet returns the value of key, generating it with fn and storing it when the entry does not exist.
func (*Cache) IncrFloat ¶
IncrFloat increments the float stored at key by value and returns the resulting value.
func (*Cache) IncrInt ¶
IncrInt increments the integer stored at key by value and returns the resulting value.
func (*Cache) Set ¶
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 ¶
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 ¶
WithCredentials sets the client certificate, the client private key and the CA certificate. Each argument is a file path.
func WithMaxExpiration ¶
WithMaxExpiration sets the maximum expiration time. Non-positive values are ignored.
func WithMaxRetries ¶
WithMaxRetries sets the maximum number of retries.
func WithMinExpiration ¶
WithMinExpiration sets the minimum expiration time. Non-positive values are ignored.
func WithNilExpiration ¶
WithNilExpiration sets the expiration time of a cached nil. Non-positive values are ignored.
func WithNilValue ¶
WithNilValue sets the placeholder value that marks a cached nil.
func WithPassword ¶
WithPassword sets the password used for authentication.
func WithUsername ¶
WithUsername sets the username used for authentication.