redisstore

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULT = time.Duration(0)
	FOREVER = time.Duration(-1)
)

Variables

View Source
var (
	ErrCacheMiss  = errors.New("cache: key not found")
	ErrNotStored  = errors.New("cache: not stored")
	ErrNotSupport = errors.New("cache: not support")
)

Functions

This section is empty.

Types

type CacheStore

type CacheStore interface {
	// Get retrieves an item from the cache. Returns the item or nil, and a bool indicating
	// whether the key was found.
	Get(key string, value interface{}) error

	// Set sets an item to the cache, replacing any existing item.
	Set(key string, value interface{}, expire time.Duration) error

	// Add adds an item to the cache only if an item doesn't already exist for the given
	// key, or if the existing item has expired. Returns an error otherwise.
	Add(key string, value interface{}, expire time.Duration) error

	// Replace sets a new value for the cache key only if it already exists. Returns an
	// error if it does not.
	Replace(key string, data interface{}, expire time.Duration) error

	// Delete removes an item from the cache. Does nothing if the key is not in the cache.
	Delete(key string) error

	// Increment increments a real number, and returns error if the value is not real
	Increment(key string, data uint64) (uint64, error)

	// Decrement decrements a real number, and returns error if the value is not real
	Decrement(key string, data uint64) (uint64, error)

	// Flush seletes all items from the cache.
	Flush() error
}

CacheStore is the interface of a cache backend

type RedisStore

type RedisStore struct {
	// contains filtered or unexported fields
}

RedisStore represents the cache with redis persistence

func NewRedisCache

func NewRedisCache(host string, port int, password string, database int, defaultExpiration time.Duration) *RedisStore

NewRedisCache returns a RedisStore until redigo supports sharding/clustering, only one host will be in hostList

func NewRedisCacheWithPool

func NewRedisCacheWithPool(pool *redis.Pool, defaultExpiration time.Duration) *RedisStore

NewRedisCacheWithPool returns a RedisStore using the provided pool until redigo supports sharding/clustering, only one host will be in hostList

func (*RedisStore) Add

func (c *RedisStore) Add(key string, value interface{}, expires time.Duration) error

Add (see CacheStore interface)

func (*RedisStore) Decrement

func (c *RedisStore) Decrement(key string, delta uint64) (newValue uint64, err error)

Decrement (see CacheStore interface)

func (*RedisStore) Delete

func (c *RedisStore) Delete(key string) error

Delete (see CacheStore interface)

func (*RedisStore) Exists

func (c *RedisStore) Exists(key string) bool

func (*RedisStore) Flush

func (c *RedisStore) Flush() error

Flush (see CacheStore interface)

func (*RedisStore) Get

func (c *RedisStore) Get(key string, ptrValue interface{}) error

Get (see CacheStore interface)

func (*RedisStore) Increment

func (c *RedisStore) Increment(key string, delta uint64) (uint64, error)

Increment (see CacheStore interface)

func (*RedisStore) Replace

func (c *RedisStore) Replace(key string, value interface{}, expires time.Duration) error

Replace (see CacheStore interface)

func (*RedisStore) Set

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

Set (see CacheStore interface)

func (*RedisStore) SetExpire

func (c *RedisStore) SetExpire(key string, expires time.Duration) bool

Jump to

Keyboard shortcuts

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