Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddCleanTask ¶ added in v1.0.18
AddCleanTask adds a clean task on given keys.
func TotalWeights ¶ added in v1.0.18
TotalWeights returns the total weights of given nodes.
Types ¶
type Cache ¶ added in v1.0.18
type Cache interface { Del(keys ...string) error Get(key string, v interface{}) error IsNotFound(err error) bool Set(key string, v interface{}) error SetWithExpire(key string, v interface{}, expire time.Duration) error Take(v interface{}, key string, query func(v interface{}) error) error TakeWithExpire(v interface{}, key string, query func(v interface{}, expire time.Duration) error) error }
Cache interface is used to define the cache implementation.
func New ¶ added in v1.1.5
func New(c ClusterConf, barrier syncx.SharedCalls, st *Stat, errNotFound error, opts ...Option) Cache
New returns a Cache.
func NewNode ¶ added in v1.1.5
func NewNode(rds *redis.Redis, barrier syncx.SharedCalls, st *Stat, errNotFound error, opts ...Option) Cache
NewNode returns a cacheNode. rds is the underlying redis node or cluster. barrier is the barrier that maybe shared with other cache nodes on cache cluster. st is used to stat the cache. errNotFound defines the error that returned on cache not found. opts are the options that customize the cacheNode.
type ClusterConf ¶ added in v1.0.18
type ClusterConf []NodeConf
A ClusterConf is the config of a redis cluster that used as cache.
type Option ¶
type Option func(o *Options)
Option defines the method to customize an Options.
func WithExpiry ¶
WithExpiry returns a func to customize a Options with given expiry.
func WithNotFoundExpiry ¶
WithNotFoundExpiry returns a func to customize a Options with given not found expiry.
type Stat ¶ added in v1.1.5
type Stat struct { // export the fields to let the unit tests working, // reside in internal package, doesn't matter. Total uint64 Hit uint64 Miss uint64 DbFails uint64 // contains filtered or unexported fields }
A Stat is used to stat the cache.
func (*Stat) IncrementDbFails ¶ added in v1.1.5
func (s *Stat) IncrementDbFails()
IncrementDbFails increments the db fail count.
func (*Stat) IncrementHit ¶ added in v1.1.5
func (s *Stat) IncrementHit()
IncrementHit increments the hit count.
func (*Stat) IncrementMiss ¶ added in v1.1.5
func (s *Stat) IncrementMiss()
IncrementMiss increments the miss count.
func (*Stat) IncrementTotal ¶ added in v1.1.5
func (s *Stat) IncrementTotal()
IncrementTotal increments the total count.