Documentation
¶
Index ¶
- Variables
- func WrapMessageQueueExtractor(c CacheExtracter) []byte
- type CacheExtracter
- type DistributedCache
- type LocalCache
- type MultiCache
- func (c *MultiCache) Delete(ctx context.Context, keys ...string) error
- func (c *MultiCache) DeleteWithMutex(ctx context.Context, key string) error
- func (c *MultiCache) Get(ctx context.Context, key string) ([]byte, error)
- func (c *MultiCache) GetWithMutex(ctx context.Context, key string) ([]byte, error)
- func (c *MultiCache) RegisterRocketmq(pc rocketmq.PushConsumer, topic string) error
- func (c *MultiCache) Set(ctx context.Context, key string, value []byte) error
- func (c *MultiCache) SetWithMutex(ctx context.Context, key string, value []byte) error
- func (c *MultiCache) SetWithVersionMutex(ctx context.Context, key string, value []byte, version int64) error
- func (c *MultiCache) Stats() bigcache.Stats
- type OptionFunc
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrRecordNotFound = errors.New("缓存记录不存在") ErrBadExpireTime = errors.New("分布式缓存的过期时间不得早于本地缓存") ErrDeleteKeyFailed = errors.New("key删除失败") ErrBadMultiCache = errors.New("分布式锁暂不可用") ErrDirtyData = errors.New("读入的数据为脏数据") )
View Source
var ( ErrTurnConsumerFailed = errors.New("更换消费者失败") ErrExtractFailed = errors.New("无法获取version和key信息") )
Functions ¶
func WrapMessageQueueExtractor ¶
func WrapMessageQueueExtractor(c CacheExtracter) []byte
Types ¶
type CacheExtracter ¶
type DistributedCache ¶
type DistributedCache struct {
*redis.ClusterClient
}
func MustNewDistributedCache ¶
func MustNewDistributedCache(addrs []string, conf *redis.ClusterOptions) *DistributedCache
type LocalCache ¶
func MustNewLocalCache ¶
func MustNewLocalCache(conf *bigcache.Config) *LocalCache
type MultiCache ¶
type MultiCache struct { Ctx context.Context EnableTracing bool //该Expire只能为distributedCache设置,localCache一旦设置之后无法改变 ExpireTime time.Duration //使用版本控制将带来更高的一致性,但是需要Set系列的函数传入的data是可以得到version字段的 //暂时只支持json UseVersionControll bool RocketmqConsumer rocketmq.PushConsumer // contains filtered or unexported fields }
func MustNewMultiCache ¶
func MustNewMultiCache(ctx context.Context, dc *DistributedCache, lc *LocalCache, opts ...OptionFunc) *MultiCache
默认会将使用的分布式缓存作为分布式锁
func (*MultiCache) Delete ¶
func (c *MultiCache) Delete(ctx context.Context, keys ...string) error
本包不建议在希望最终一致性的情况下直接使用该Delete函数
func (*MultiCache) DeleteWithMutex ¶
func (c *MultiCache) DeleteWithMutex(ctx context.Context, key string) error
func (*MultiCache) GetWithMutex ¶
func (*MultiCache) RegisterRocketmq ¶
func (c *MultiCache) RegisterRocketmq(pc rocketmq.PushConsumer, topic string) error
func (*MultiCache) SetWithMutex ¶
func (*MultiCache) SetWithVersionMutex ¶
func (c *MultiCache) SetWithVersionMutex(ctx context.Context, key string, value []byte, version int64) error
结合版本控制和分布式锁机制,注意value参数中应当也要有version字段,多出来的version参数则是避免再次unmarshal得到
func (*MultiCache) Stats ¶
func (c *MultiCache) Stats() bigcache.Stats
type OptionFunc ¶
type OptionFunc func(*MultiCache)
func WithExpireTime ¶
func WithExpireTime(t time.Duration) OptionFunc
func WithRedlock ¶
func WithRedlock(r *redlock.RedLock) OptionFunc
Click to show internal directories.
Click to hide internal directories.