Documentation
¶
Overview ¶
Package cache provides tools for caching data.
Index ¶
- type CommonProvider
- func (p *CommonProvider) Close() error
- func (p *CommonProvider) Decr(ctx context.Context, key string) (int64, error)
- func (p *CommonProvider) DecrBy(ctx context.Context, key string, decrement int64) (int64, error)
- func (p *CommonProvider) Del(ctx context.Context, keys ...string) error
- func (p *CommonProvider) DelByPattern(ctx context.Context, pattern string, batchSize *int64) error
- func (p *CommonProvider) Get(ctx context.Context, key string) (string, error)
- func (p *CommonProvider) GetDel(ctx context.Context, key string) (string, error)
- func (p *CommonProvider) GetEx(ctx context.Context, key string, expiration time.Duration) (string, error)
- func (p *CommonProvider) Incr(ctx context.Context, key string) (int64, error)
- func (p *CommonProvider) IncrBy(ctx context.Context, key string, value int64) (int64, error)
- func (p *CommonProvider) Ping(ctx context.Context) (string, error)
- func (p *CommonProvider) Set(ctx context.Context, key string, value any, expiration time.Duration) error
- func (p *CommonProvider) SetNX(ctx context.Context, key string, value any, expiration time.Duration) error
- type Option
- func WithClientName(clientName string) Option
- func WithConnectionMaxIdleTime(connectionMaxIdleTime time.Duration) Option
- func WithConnectionMaxLifetime(connectionMaxLifetime time.Duration) Option
- func WithContextTimeoutEnabled(contextTimeoutEnabled bool) Option
- func WithDB(db int) Option
- func WithDialTimeout(dialTimeout time.Duration) Option
- func WithHost(host string) Option
- func WithMaxActiveConnections(maxActiveConnections int) Option
- func WithMaxIdleConnections(maxIdleConnections int) Option
- func WithMaxRetries(maxRetries int) Option
- func WithMaxRetryBackoff(maxRetryBackoff time.Duration) Option
- func WithMinIdleConnections(minIdleConnections int) Option
- func WithMinRetryBackoff(minRetryBackoff time.Duration) Option
- func WithPassword(password string) Option
- func WithPoolFIFO(poolFIFO bool) Option
- func WithPoolSize(poolSize int) Option
- func WithPoolTimeout(poolTimeout time.Duration) Option
- func WithPort(port int) Option
- func WithReadTimeout(readTimeout time.Duration) Option
- func WithUsername(username string) Option
- func WithWriteTimeout(writeTimeout time.Duration) Option
- type Provider
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) Del ¶
func (p *CommonProvider) Del(ctx context.Context, keys ...string) error
Del deletes keys.
func (*CommonProvider) DelByPattern ¶ added in v1.11.1
DelByPattern deletes all keys, which matches provided pattern.
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) Ping ¶
func (p *CommonProvider) Ping(ctx context.Context) (string, error)
Ping checks status.
type Option ¶
type Option func(options *options) error
Option represents golang functional option pattern func for configuration.
func WithClientName ¶
func WithDialTimeout ¶
func WithMaxIdleConnections ¶
func WithMaxRetries ¶
func WithMaxRetryBackoff ¶
func WithMinIdleConnections ¶
func WithMinRetryBackoff ¶
func WithPassword ¶
func WithPoolFIFO ¶
func WithPoolSize ¶
func WithPoolTimeout ¶
func WithReadTimeout ¶
func WithUsername ¶
func WithWriteTimeout ¶
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.
Click to show internal directories.
Click to hide internal directories.