Documentation ¶
Index ¶
- Constants
- Variables
- func Marshal(value interface{}) ([]byte, error)
- func NewLockKey(key string) (lockKey string)
- func StructToRedisHash(ctx context.Context, cli redis.Cmdable, key string, data interface{}) error
- func Unmarshal(b []byte, value interface{}) error
- type Cache
- func (cd *Cache) Delete(ctx context.Context, key string) error
- func (cd *Cache) DeleteFromLocalCache(key string)
- func (cd *Cache) Exists(ctx context.Context, key string) bool
- func (cd *Cache) Get(ctx context.Context, key string, value interface{}) error
- func (cd *Cache) GetS(ctx context.Context, keys []string, skipLocalCache bool) ([][]byte, error)
- func (cd *Cache) GetSkippingLocalCache(ctx context.Context, key string, value interface{}) error
- func (cd *Cache) Marshal(value interface{}) ([]byte, error)
- func (cd *Cache) Once(item *Item) error
- func (cd *Cache) Set(ctx context.Context, item *Item) error
- func (cd *Cache) SetS(ctx context.Context, items []*Item) error
- func (cd *Cache) Unmarshal(b []byte, value interface{}) error
- type DealWith
- type DelayedQueue
- type Item
- type LocalCache
- type LockType
- type MarshalFunc
- type Options
- type Pagination
- type RedisLock
- type SortSet
- type TinyLFU
- type UnmarshalFunc
Constants ¶
View Source
const ( Writer LockType = 1 Read LockType = 2 DefaultLockTtl = time.Minute * 10 DefaultLockValue = "0" )
Variables ¶
View Source
var (
ErrCacheMiss = errors.New("cache: key is missing")
)
View Source
var ErrUnknownType = errors.New("未知数据类型")
Functions ¶
func StructToRedisHash ¶
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
func (*Cache) DeleteFromLocalCache ¶
func (*Cache) GetSkippingLocalCache ¶
GetSkippingLocalCache gets the value for the given key skipping local cache.
func (*Cache) Once ¶
Once gets the item.Value for the given item.Key from the cache or executes, caches, and returns the results of the given item.Func, making sure that only one execution is in-flight for a given item.Key at a time. If a duplicate comes in, the duplicate caller waits for the original to complete and receives the same results.
type DelayedQueue ¶
type DelayedQueue interface { Put(ctx context.Context, key string, z []*redis.Z, ttl time.Duration) error DealWithOnce(ctx context.Context, key string, min, max float64, ttl time.Duration) error DealWithMultiple(ctx context.Context, key string, min, max float64, ttl time.Duration) error }
func NewDelayedQueue ¶
func NewDelayedQueue(rd *rd.Client, fun DealWith) DelayedQueue
type Item ¶
type Item struct { Ctx context.Context Key string Value interface{} // TTL is the cache expiration time. // Default TTL is 1 hour. TTL time.Duration // Do returns value to be cached. Do func(*Item) (interface{}, error) // SetXX only sets the key if it already exists. SetXX bool // SetNX only sets the key if it does not already exist. SetNX bool // SkipLocalCache skips local cache as if it is not set. SkipLocalCache bool }
type LocalCache ¶
type MarshalFunc ¶
type Options ¶
type Options struct { Redis redis.Cmdable LocalCache LocalCache StatsEnabled bool Marshal MarshalFunc Unmarshal UnmarshalFunc }
type Pagination ¶
type RedisLock ¶
type RedisLock interface { // 加锁, 返回加锁是否成功 TryLock(ctx context.Context, key string, val interface{}, ttl time.Duration) (bool, []byte, error) // 解锁 UnLock(ctx context.Context, key string, val interface{}) error // 等待释放锁 WaitUnLock(ctx context.Context, key string) (err error) // 续约 RenewLock(ctx context.Context, key string, value interface{}, ttl time.Duration) (err error) // 加锁, 如果有锁,等待锁释放再添加锁 WaitLock(ctx context.Context, key string, val interface{}, ttl time.Duration) (bool, error) }
func NewRedisLock ¶
func NewRedisLock(redis redis.Cmdable) RedisLock
type SortSet ¶
type SortSet interface { // 添加元素 CacheIndexAdd(ctx context.Context, key string, value []*redis.Z) (result int64, err error) // 查询,通过分页 CacheIndexGetByOrder(ctx context.Context, key string, page *Pagination) (result []string, err error) // 查询,通过分数分页 CacheIndexGetByScore(ctx context.Context, key string, page *Pagination) (result []string, err error) // 获取有序集合数量 CacheGetSortSetCount(ctx context.Context, key string) (result int64, err error) // 判断元素是否存在有序集合 CacheExistsSortSet(ctx context.Context, key, value string) (result bool, err error) // 删除有序集合元素 CacheDelMember(ctx context.Context, key, value string) (err error) }
func NewCacheIndex ¶
func NewCacheIndex(redis redis.Cmdable) SortSet
type TinyLFU ¶
type TinyLFU struct {
// contains filtered or unexported fields
}
func (*TinyLFU) UseRandomizedTTL ¶
type UnmarshalFunc ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.