Documentation
¶
Index ¶
Constants ¶
const KEY_PREFIX_EXPIRED = "expired:"
const KEY_PREFIX_LOCK = "locks:"
const KEY_PREFIX_SHADOW = "shadow:"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheMap ¶
type CacheMap struct {
// contains filtered or unexported fields
}
func NewCacheMap ¶
type CacheRedis ¶
type CacheRedis struct {
// contains filtered or unexported fields
}
func NewCacheRedis ¶
func NewCacheRedis(config *schema.CacheConf) *CacheRedis
func (*CacheRedis) Store ¶
func (c *CacheRedis) Store(ctx context.Context, key string, value interface{}, expireAt *time.Time) error
Store any element into Redis server. The KEY should be string and the VALUE should be possible to be marshaled into json format before storing. If you want to set specific experation time, you need to set expireAt. If not, you can just set expireAt as nil and the duration in cache config will be used.
type MutexPool ¶
type MutexPool struct {
// contains filtered or unexported fields
}
Provide a pool which consists of sync.Mutex lock for keys. This pool is implemented based on cacheMap and the lock in this pool is valid within the process (local).
func NewMutexPool ¶
type RedisLockPool ¶
type RedisLockPool struct {
// contains filtered or unexported fields
}
Provide a pool which consists of redsync.Mutex lock for keys. This pool is implemented based on Redsync, CacheMap and Redis Cluster. The lock in this pool is valid within the same redis cluster (distributed). Redsync is a Redis-based distributed mutual exclusion lock implementation for Go as a library. CacheMap is used for caching redsync.Mutex locks to avoid from creating the same lock multiple times. Redis Cluster is used for storing the lock information.
func NewRedisLockPool ¶
func NewRedisLockPool(config *schema.CacheConf) (lockPool *RedisLockPool)
func (*RedisLockPool) Lock ¶
func (l *RedisLockPool) Lock(key string) (err error)
Obtain a lock for given key. After this is successful, no one else can obtain the same lock (the same mutex name) until it is unlocked.
func (*RedisLockPool) TryLock ¶
func (l *RedisLockPool) TryLock(key string) (err error)
Obtain a lock for given key. After this is successful, no one else can obtain the same lock (the same mutex name) until it is unlocked. And also TryLock only attempts to lock m once and returns immediately regardless of success or failure without retrying.
func (*RedisLockPool) Unlock ¶
func (l *RedisLockPool) Unlock(key string, lockError error) (ok bool, err error)
Release the lock and then other processes or threads can obtain a lock. Ok will represent the status of unlocking. lockError is the error which is returned by the Lock or TryLock. If lockError is not nil, Unlock will handle it based on error type. ok will be true and err will be nil if there was no issue on Unlock even though lockError is not nil so, the Unlock does not happen actually.