Documentation ¶
Index ¶
- Constants
- Variables
- type FreeCache
- type KVCache
- type LockElem
- type RedClient
- type RedLock
- func (r *RedLock) Lock(ctx context.Context, resource string, ttl time.Duration) (int64, error)
- func (r *RedLock) SetCache(cacheType string, opts map[string]interface{})
- func (r *RedLock) SetRetryCount(count int)
- func (r *RedLock) SetRetryDelay(delay int)
- func (r *RedLock) UnLock(ctx context.Context, resource string) error
- type SimpleCache
Constants ¶
View Source
const ( CacheTypeSimple = "simple" CacheTypeFreeCache = "freecache" )
kv cache types
View Source
const ( OptDisableGC = "opt-disable-gc" OptGCInterval = "opt-gc-interval" OptCacheSize = "opt-cache-size" )
kv cache options
View Source
const ( // DefaultRetryCount is the max retry times for lock acquire DefaultRetryCount = 10 // DefaultRetryDelay is upper wait time in millisecond for lock acquire retry DefaultRetryDelay = 200 // ClockDriftFactor is clock drift factor, more information refers to doc ClockDriftFactor = 0.01 // UnlockScript is redis lua script to release a lock UnlockScript = `` /* 155-byte string literal not displayed */ )
Variables ¶
View Source
var ( // ErrLockSingleRedis represents error when acquiring lock on a single redis ErrLockSingleRedis = errors.New("set lock on single redis failed") // ErrAcquireLock means acquire lock failed after max retry time ErrAcquireLock = errors.New("failed to require lock") )
Functions ¶
This section is empty.
Types ¶
type FreeCache ¶
type FreeCache struct {
// contains filtered or unexported fields
}
FreeCache is a wrapper of freecache.Cache
func NewFreeCache ¶
NewFreeCache returns a new FreeCache instance
type KVCache ¶
type KVCache interface { // Set sets the key value with its expiry in nanoseconds Set(key, val string, expiry int64) (*LockElem, error) // Get queries LockElem from given key Get(key string) (*LockElem, error) // Delete removes the LockElem with given key from storage Delete(key string) // Size returns element count in kv storage Size() int }
KVCache defines interface for redlock key value storage
func NewCacheImpl ¶
NewCacheImpl returns a KVCache implementation based on given cache type
type LockElem ¶
type LockElem struct { Val string `json:"val"` Expiry int64 `json:"expiry"` Ts time.Time `json:"ts"` }
LockElem keeps a lock element
type RedClient ¶
type RedClient struct {
// contains filtered or unexported fields
}
RedClient holds client to redis
type RedLock ¶
type RedLock struct {
// contains filtered or unexported fields
}
RedLock holds the redis lock
func (*RedLock) SetRetryCount ¶
SetRetryCount sets acquire lock retry count
func (*RedLock) SetRetryDelay ¶
SetRetryDelay sets acquire lock retry max internal in millisecond
type SimpleCache ¶
type SimpleCache struct {
// contains filtered or unexported fields
}
SimpleCache is the most native implementation of KVCache interface
func NewSimpleCache ¶
func NewSimpleCache(opts map[string]interface{}) *SimpleCache
NewSimpleCache creates a new SimpleCache object
func (*SimpleCache) Delete ¶
func (sc *SimpleCache) Delete(key string)
Delete implements KVCache.Delete
func (*SimpleCache) Get ¶
func (sc *SimpleCache) Get(key string) (*LockElem, error)
Get implements KVCache.Get
Click to show internal directories.
Click to hide internal directories.