Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrLockExists = errors.New("lock was not created because one was already present")
ErrLockExists indicates that a lock was not created because one was already present. This error is returned after the old lock is deleted or expired.
var ErrNotFound = errors.New("item not found")
ErrNotFound is returned when an item is not present in cache.
Functions ¶
This section is empty.
Types ¶
type InMemoryCache ¶
type InMemoryCache map[string]item
InMemoryCache is an in memory cache used as a backup when Redis is unavailable.
func NewInMemoryCache ¶
func NewInMemoryCache() InMemoryCache
NewInMemoryCache initializes and returns an InMemoryCache.
func (InMemoryCache) Del ¶
func (c InMemoryCache) Del(key string) error
Del deletes an item from cache.
func (InMemoryCache) Get ¶
func (c InMemoryCache) Get(key string, value interface{}) error
Get retrieves an item from cache. `key` is case insensitive. `value` is a pointer to the variable that will receive the data. `error` is ErrNotFound when no value is found.
type LockManager ¶
type LockManager struct {
// contains filtered or unexported fields
}
LockManager manage locks using Cache, to prevent multiple expensive actions to be run at the same time.
func NewLockManager ¶
func NewLockManager(cache cache, retryDelay time.Duration) *LockManager
NewLockManager initializes and returns a LockManager for Redis.
func (*LockManager) Create ¶
func (l *LockManager) Create(name string, expiration time.Duration) error
Create creates a lock to prevent having multiple instances of this service doing an expensive action at the same time. If a lock already exists, the function will not create one, it will wait until the existing one is deleted or expired before returning ErrLockExists.
func (*LockManager) Delete ¶
func (l *LockManager) Delete(name string)
Delete removes a lock for the provided name.
type RedisCache ¶
type RedisCache struct {
// contains filtered or unexported fields
}
RedisCache contains redis client.
func NewRedisCache ¶
func NewRedisCache(host, port string, version int) *RedisCache
NewRedisCache initializes and returns a RedisCache.
func (*RedisCache) Get ¶
func (c *RedisCache) Get(key string, value interface{}) error
Get retrieves an item from cache. `key` is case insensitive. `value` is a pointer to the variable that will receive the data. `error` is ErrNotFound when no value is found.