storage

package
v1.13.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
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.

func (InMemoryCache) MSet

func (c InMemoryCache) MSet(pairs map[string]interface{}, ttl time.Duration) error

MSet writes items to cache in bulk.

func (InMemoryCache) Set

func (c InMemoryCache) Set(key string, value interface{}, ttl time.Duration) error

Set writes data to cache. `key` is case insensitive.

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) Del

func (c *RedisCache) Del(key string) error

Del deletes an item from cache.

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.

func (*RedisCache) MSet

func (c *RedisCache) MSet(pairs map[string]interface{}, ttl time.Duration) error

MSet writes items to cache in bulk.

func (*RedisCache) Set

func (c *RedisCache) Set(key string, value interface{}, ttl time.Duration) error

Set writes data to cache with the specified lifespan. `key` is case insensitive.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL