Documentation
¶
Index ¶
- Variables
- func LocalClear(key string)
- func LocalGet(key string) (any, bool)
- func LocalRemember[T any](key string, ttl time.Duration, fn func() (T, error)) (T, error)
- func LocalSet(key string, val any, ttl time.Duration)
- type Cache
- type Redis
- func (r *Redis) Forget(ctx context.Context, key string) error
- func (r *Redis) Get(ctx context.Context, key string) ([]byte, error)
- func (r *Redis) Has(ctx context.Context, key string) (bool, error)
- func (r *Redis) Remember(ctx context.Context, key string, ttl time.Duration, fn func() ([]byte, error)) ([]byte, error)
- func (r *Redis) Set(ctx context.Context, key string, value any, expiration time.Duration) error
- func (r *Redis) SetOption(opt func(*redis.Options))
- type RedisOptionFunc
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultExpiration = time.Hour
View Source
var (
ErrNotExist = errors.New("cache does not exist")
)
Functions ¶
func LocalClear ¶
func LocalClear(key string)
func LocalRemember ¶
Types ¶
type Cache ¶
type Cache interface { Has(ctx context.Context, key string) (bool, error) Set(ctx context.Context, key string, value any, expiration time.Duration) error Get(ctx context.Context, key string) ([]byte, error) Forget(ctx context.Context, key string) error Remember(ctx context.Context, key string, ttl time.Duration, fn func() ([]byte, error)) ([]byte, error) }
func NewRedis ¶
func NewRedis(addr string, opts ...RedisOptionFunc) Cache
func NewRedisFromConfig ¶
type Redis ¶
type Redis struct {
// contains filtered or unexported fields
}
type RedisOptionFunc ¶
type RedisOptionFunc func(*Redis)
func SetDB ¶
func SetDB(db int) RedisOptionFunc
func SetPassword ¶
func SetPassword(password string) RedisOptionFunc
func SetPrefix ¶
func SetPrefix(prefix string) RedisOptionFunc
Click to show internal directories.
Click to hide internal directories.