redis

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2016 License: MIT Imports: 8 Imported by: 0

Documentation

Index

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 (
	RedisKeyIndex = make(map[string]RedisKey)
	RedisKeys     = []RedisKey{
		{/* 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 (
	// ErrFailed is returned when lock cannot be acquired
	ErrFailed = errors.New("failed to acquire lock")
)

Functions

This section is empty.

Types

type Locker

type Locker interface {
	Lock(string) error
	Unlock(string) bool
}

Locker interface with Lock returning an error when lock cannot be aquired

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.

func NewMutex

func NewMutex(genericNodes []Pool) *Mutex

NewMuter initializes a new regex on a redis pool

func (*Mutex) Lock

func (m *Mutex) Lock(key string) error

Lock will put a lock key in redis In case it returns an error on failure, you may retry to acquire the lock by calling this method again.

func (*Mutex) Unlock

func (m *Mutex) Unlock(key string) bool

Unlock will delete the lock key It returns the status of the unlock

type Pool

type Pool interface {
	Get() redis.Conn
}

Pool is a generic connection pool

type Redis

type Redis struct {
	// Redis address and max pool connections
	Protocol       string
	Address        string
	MaxIdle        int
	MaxConnections int
}

func (*Redis) NewRedisCache

func (r *Redis) NewRedisCache()

NewRedisCache creates a new pool

type RedisKey

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

func NewKey

func NewKey(name string) *RedisKey

NewKey returns a key from the index or nil if it doesnt exist

func (*RedisKey) Delete

func (r *RedisKey) Delete() (err error)

deletes a key

func (*RedisKey) Get

func (r *RedisKey) Get() (result []byte, err error)

gets a key, automatically handles hash types

func (*RedisKey) Set

func (r *RedisKey) Set(data []byte) (err error)

sets a key, handles hash types and expiry

func (*RedisKey) SetKey

func (r *RedisKey) SetKey(ids ...string) *RedisKey

populates the fields in a key and sets the hash id

func (*RedisKey) String

func (r *RedisKey) String() string

return a string version of the key

type RedisKeyer

type RedisKeyer interface {
	SetKey(ids ...string) *RedisKey
	Get() (result []byte, err error)
	Set(data []byte) (err error)
	Delete() (err error)
	String() string
}

type RedisStore

type RedisStore struct {
	Pool  *redis.Pool
	Mutex *Mutex
}

RedisStore holds a handle to the Redis pool

var (
	RedisCache   RedisStore
	ErrCacheMiss = errors.New("cache: key not found.")
)

func (*RedisStore) Delete

func (c *RedisStore) Delete(key ...interface{}) (err error)

Delete will delete a key

func (*RedisStore) Expire

func (c *RedisStore) Expire(key string, timeout uint) (err error)

will set expire on a redis key

func (*RedisStore) Flush

func (c *RedisStore) Flush() (err error)

Flush will call flushall and delete all keys

func (*RedisStore) Get

func (c *RedisStore) Get(key string) (result []byte, err error)

Get will retrieve a key

func (*RedisStore) HGet

func (c *RedisStore) HGet(key string, value string) (result []byte, err error)

HGet will retrieve a hash

func (*RedisStore) HMSet

func (c *RedisStore) HMSet(key string, value string, result []byte) (err error)

HMSet will set a hash

func (*RedisStore) Incr

func (c *RedisStore) Incr(key string) (result int, err error)

will increment a redis key

func (*RedisStore) Lock

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

lock our shared mutex

func (*RedisStore) Set

func (c *RedisStore) Set(key string, result []byte) (err error)

Set will set a single record

func (*RedisStore) SetEx

func (c *RedisStore) SetEx(key string, timeout uint, result []byte) (err error)

Set will set a single record

func (*RedisStore) Unlock

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

unlock our shared mutex

type RedisStorer

type RedisStorer 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)
}

Jump to

Keyboard shortcuts

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