Documentation
¶
Index ¶
- Constants
- Variables
- func NewRedisMock()
- func SetCacheInitialized()
- type Key
- type Keyer
- type Locker
- type Mutex
- type Pool
- type Redis
- type Store
- func (c *Store) Delete(key ...interface{}) (err error)
- func (c *Store) Expire(key string, timeout uint) (err error)
- func (c *Store) Flush() (err error)
- func (c *Store) Get(key string) ([]byte, error)
- func (c *Store) HGet(key string, value string) ([]byte, error)
- func (c *Store) HMSet(key string, value string, result []byte) (err error)
- func (c *Store) Incr(key string) (result int, err error)
- func (c *Store) Lock(key string) error
- func (c *Store) Set(key string, result []byte) (err error)
- func (c *Store) SetEx(key string, timeout uint, result []byte) (err error)
- func (c *Store) Unlock(key string) bool
- type Storer
Constants ¶
View Source
const ( // DefaultExpiry is used when Mutex Duration is 0 DefaultExpiry = 6 * time.Second // DefaultTries is used when Mutex Duration is 0 DefaultTries = 16 // DefaultDelay is used when Mutex Delay is 0 DefaultDelay = 512 * time.Millisecond // DefaultFactor is used when Mutex Factor is 0 DefaultFactor = 0.01 )
Variables ¶
View Source
var ( // ErrKeyNotSet returns if the key was not set properly ErrKeyNotSet = errors.New("key not set") // RedisKeyIndex holds a searchable index of keys RedisKeyIndex = make(map[string]Key) // RedisKeys is a slice of all the explicit keys RedisKeys = []Key{ {/* contains filtered or unexported fields */}, {/* contains filtered or unexported fields */}, {/* contains filtered or unexported fields */}, {/* contains filtered or unexported fields */}, {/* contains filtered or unexported fields */}, {/* contains filtered or unexported fields */}, {/* contains filtered or unexported fields */}, {/* contains filtered or unexported fields */}, {/* contains filtered or unexported fields */}, {/* contains filtered or unexported fields */}, {/* contains filtered or unexported fields */}, {/* contains filtered or unexported fields */}, } )
View Source
var ErrCacheNotInitialized = errors.New("redis cache not initialized")
ErrCacheNotInitialized is returned when Cache is not yet initialized
View Source
var ( // ErrFailed is returned when lock cannot be acquired ErrFailed = errors.New("failed to acquire lock") )
Functions ¶
func NewRedisMock ¶ added in v1.3.0
func NewRedisMock()
NewRedisMock returns a fake redis pool for testing
func SetCacheInitialized ¶ added in v1.9.0
func SetCacheInitialized()
SetCacheInitialized marks the cache as initialized
Types ¶
type Key ¶ added in v1.3.0
type Key struct {
// contains filtered or unexported fields
}
Key holds an explicit keys data
type Keyer ¶ added in v1.3.0
type Keyer interface {
SetKey(ids ...string) *Key
Get() (result []byte, err error)
Set(data []byte) (err error)
Delete() (err error)
String() string
}
Keyer describes the explicit key functions
type Mutex ¶
type Mutex struct {
Expiry time.Duration // Duration for which the lock is valid, DefaultExpiry if 0
Tries int // Number of attempts to acquire lock before admitting failure, DefaultTries if 0
Delay time.Duration // Delay between two attempts to acquire lock, DefaultDelay if 0
Factor float64 // Drift factor, DefaultFactor if 0
Quorum int // Quorum for the lock, set to len(addrs)/2+1 by NewMutex()
// contains filtered or unexported fields
}
A Mutex is a mutual exclusion lock.
type Redis ¶
type Redis struct {
// Redis address and max pool connections
Protocol string
Address string
MaxIdle int
MaxConnections int
}
Redis holds connection options for redis
type Store ¶ added in v1.3.0
type Store struct {
Pool Pool
Mutex *Mutex
Mock *redigomock.Conn
}
Store holds a handle to the Redis pool
type Storer ¶ added in v1.3.0
type Storer interface {
Lock(key string) error
Unlock(key string) bool
Get(key string) (result []byte, err error)
HGet(key string, value string) (result []byte, err error)
Set(key string, result []byte) (err error)
SetEx(key string, timeout uint, result []byte) (err error)
HMSet(key string, value string, result []byte) (err error)
Delete(key ...interface{}) (err error)
Flush() (err error)
Incr(key string) (result int, err error)
Expire(key string, timeout uint) (err error)
}
Storer defines custom methods for redis operations
Click to show internal directories.
Click to hide internal directories.