Documentation ¶
Index ¶
- Variables
- func FromSkipCacheContext(ctx context.Context) (skip bool)
- func NewCacheContext(ctx context.Context, cache Cacher) context.Context
- func NewSkipCacheContext(ctx context.Context, skip ...bool) context.Context
- func RandomTimeHour(min, max int64) time.Duration
- func RandomTimeMinute(min, max int64) time.Duration
- func RandomTimeSecond(min, max int64) time.Duration
- type Cache
- type CacheKey
- type Cacher
- type ExpiryFunc
- type Geter
- type JSONSerialize
- type Keyer
- type Option
- type Options
- type QueryFunc
- type RedisCache
- func (r *RedisCache) DelRangeKey(ctx context.Context, setKey string) (err error)
- func (r *RedisCache) Get(ctx context.Context, key string, v interface{}) (err error)
- func (r *RedisCache) GetBytes(ctx context.Context, key string) (bytes []byte, err error)
- func (r *RedisCache) GetHash(ctx context.Context, key, field string) (value string)
- func (r *RedisCache) GetString(ctx context.Context, key string) (value string, err error)
- func (r *RedisCache) PushRangeKey(ctx context.Context, setKey string, keys ...string) (err error)
- func (r *RedisCache) Remove(ctx context.Context, keys ...string) (err error)
- func (r *RedisCache) RemoveMatch(ctx context.Context, match string) (err error)
- func (r *RedisCache) Set(ctx context.Context, key string, v interface{}, expiration ...time.Duration) (err error)
- func (r *RedisCache) SetBytes(ctx context.Context, key string, bytes []byte, expiration ...time.Duration) (err error)
- func (r *RedisCache) SetHash(ctx context.Context, key string, v map[string]string, ...) (err error)
- func (r *RedisCache) SetString(ctx context.Context, key string, value string, expiration ...time.Duration) (err error)
- type RedisCache2
- func (r *RedisCache2) AddRangeKey(ctx context.Context, setKey string, keys ...string) (err error)
- func (r *RedisCache2) Del(ctx context.Context, keys ...string) (err error)
- func (r *RedisCache2) DelRangeKey(ctx context.Context, setKey string) (err error)
- func (r *RedisCache2) Get(ctx context.Context, key string, v interface{}) (err error)
- func (r *RedisCache2) IsNotFound(err error) bool
- func (r *RedisCache2) Set(ctx context.Context, key string, v interface{}, expiry ...time.Duration) (err error)
- func (r *RedisCache2) Task(ctx context.Context, key string, v interface{}, query QueryFunc, ...) (err error)
- type Remover
- type Serializer
- type Seter
- type SkipCacheKey
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrDefaultNotFound = errors.New("cache: not found")
)
Functions ¶
func FromSkipCacheContext ¶
FromSkipCacheContext 从上下文中获取跳过缓存变量
func NewCacheContext ¶
NewCacheContext ...
func NewSkipCacheContext ¶
NewSkipCacheContext 创建跳过缓存到上下文
func RandomTimeHour ¶
RandomTimeHour 随机多少小时 防止缓存雪崩:设置缓存时间为范围随机,解决大量缓存在同一时间失效的问题。
func RandomTimeMinute ¶
RandomTimeMinute 随机多少分钟 防止缓存雪崩:设置缓存时间为范围随机,解决大量缓存在同一时间失效的问题。
func RandomTimeSecond ¶
RandomTimeSecond 随机多少秒 防止缓存雪崩:设置缓存时间为范围随机,解决大量缓存在同一时间失效的问题。
Types ¶
type Cache ¶
type Cache interface { Get(ctx context.Context, key string, v interface{}) (err error) Task(ctx context.Context, key string, v interface{}, query QueryFunc, expiry ...time.Duration) (err error) Set(ctx context.Context, key string, v interface{}, expiry ...time.Duration) (err error) Del(ctx context.Context, keys ...string) (err error) AddRangeKey(ctx context.Context, setKey string, keys ...string) (err error) DelRangeKey(ctx context.Context, setKey string) (err error) IsNotFound(err error) bool }
type ExpiryFunc ¶
type Geter ¶
type Geter interface { Get(ctx context.Context, key string, v interface{}) (err error) GetString(ctx context.Context, key string) (value string, err error) GetBytes(ctx context.Context, key string) (bytes []byte, err error) GetHash(ctx context.Context, key, field string) (value string) }
Geter ...
type JSONSerialize ¶
type JSONSerialize struct { }
JSONSerialize 高性能json序列化
func (JSONSerialize) Marshal ¶
func (JSONSerialize) Marshal(msg interface{}) (data []byte, err error)
Marshal ...
func (JSONSerialize) Unmarshal ¶
func (JSONSerialize) Unmarshal(data []byte, msg interface{}) (err error)
Unmarshal ...
type Option ¶
type Option func(o *Options)
func WithErrNotFound ¶
func WithExpiry ¶
func WithExpiry(expiry ExpiryFunc) Option
func WithNotFoundExpiry ¶
func WithPrefix ¶
func WithSerializer ¶
func WithSerializer(serializer Serializer) Option
type Options ¶
type Options struct { Expiry ExpiryFunc NotFoundExpiry time.Duration Prefix string Serializer Serializer ErrNotFound error }
type RedisCache ¶
type RedisCache struct { Prefix string // contains filtered or unexported fields }
RedisCache redis缓存
func NewRedisCache ¶
func NewRedisCache(redisClient *redis.Client, prefix string) *RedisCache
NewRedisCache ...
func (*RedisCache) DelRangeKey ¶
func (r *RedisCache) DelRangeKey(ctx context.Context, setKey string) (err error)
func (*RedisCache) Get ¶
func (r *RedisCache) Get(ctx context.Context, key string, v interface{}) (err error)
Get ...
func (*RedisCache) GetHash ¶
func (r *RedisCache) GetHash(ctx context.Context, key, field string) (value string)
GetHash ...
func (*RedisCache) PushRangeKey ¶
func (*RedisCache) Remove ¶
func (r *RedisCache) Remove(ctx context.Context, keys ...string) (err error)
Remove ...
func (*RedisCache) RemoveMatch ¶
func (r *RedisCache) RemoveMatch(ctx context.Context, match string) (err error)
RemoveMatch ...
func (*RedisCache) Set ¶
func (r *RedisCache) Set(ctx context.Context, key string, v interface{}, expiration ...time.Duration) (err error)
Set ...
func (*RedisCache) SetBytes ¶
func (r *RedisCache) SetBytes(ctx context.Context, key string, bytes []byte, expiration ...time.Duration) (err error)
SetBytes ...
type RedisCache2 ¶
type RedisCache2 struct {
// contains filtered or unexported fields
}
RedisCache2 redis缓存
func NewRedisCache2 ¶
func NewRedisCache2(redisClient *redis.Client, opts ...Option) *RedisCache2
NewRedisCache2 ...
func (*RedisCache2) AddRangeKey ¶
func (*RedisCache2) Del ¶
func (r *RedisCache2) Del(ctx context.Context, keys ...string) (err error)
func (*RedisCache2) DelRangeKey ¶
func (r *RedisCache2) DelRangeKey(ctx context.Context, setKey string) (err error)
func (*RedisCache2) Get ¶
func (r *RedisCache2) Get(ctx context.Context, key string, v interface{}) (err error)
func (*RedisCache2) IsNotFound ¶
func (r *RedisCache2) IsNotFound(err error) bool
type Remover ¶
type Remover interface { Remove(ctx context.Context, keys ...string) (err error) RemoveMatch(ctx context.Context, match string) (err error) }
Remover ...
type Serializer ¶
type Serializer interface { Unmarshal(data []byte, msg interface{}) (err error) Marshal(msg interface{}) (data []byte, err error) ContentType() string }
Serializer 序列化器
type Seter ¶
type Seter interface { Set(ctx context.Context, key string, v interface{}, expiration ...time.Duration) (err error) SetString(ctx context.Context, key string, value string, expiration ...time.Duration) (err error) SetBytes(ctx context.Context, key string, bytes []byte, expiration ...time.Duration) (err error) SetHash(ctx context.Context, key string, v map[string]string, expiration ...time.Duration) (err error) }
Seter ...
type SkipCacheKey ¶
type SkipCacheKey struct{}
Click to show internal directories.
Click to hide internal directories.