redis

package
v0.0.0-...-a98e843 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2017 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package redis implements a service to store data in redis. This can be used in production.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsExecutionFailed

func IsExecutionFailed(err error) bool

IsExecutionFailed asserts executionFailedError.

func IsInvalidConfig

func IsInvalidConfig(err error) bool

IsInvalidConfig asserts invalidConfigError.

func IsInvalidExecution

func IsInvalidExecution(err error) bool

IsInvalidExecution asserts invalidExecutionError.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound checks whether a redis response was empty. Therefore it checks for redigo.ErrNil and notFoundError.

ErrNil indicates that a reply value is nil.

func NewDial

func NewDial(config DialConfig) func() (redis.Conn, error)

NewDial creates a new configured redis dialer.

func NewMockDial

func NewMockDial(config MockDialConfig) func() (redis.Conn, error)

func NewPool

func NewPool(config PoolConfig) *redis.Pool

NewPool creates a new configured redis pool.

func NewPoolWithAddress

func NewPoolWithAddress(address string) *redis.Pool

Types

type Backoff

type Backoff interface {
	// NextBackOff provides the duration expected to wait before retrying an
	// action. time.Duration = -1 indicates that no more retry should be
	// attempted.
	NextBackOff() time.Duration
	// Reset sets the backoff back to its initial state.
	Reset()
}

Backoff represents the object managing backoff algorithms to retry actions.

type Config

type Config struct {
	// Dependencies.
	BackoffFactory         func() Backoff
	InstrumentorCollection *instrumentor.Collection
	LoggerService          logger.Service
	RandomService          random.Service

	// Settings.
	Address string
	Pool    *redis.Pool
	Prefix  string
}

Config represents the configuration used to create a new storage service.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig provides a default configuration to create a new storage service by best effort.

type DialConfig

type DialConfig struct {
	// Address represents the address used to connect to a redis server.
	Address string
}

DialConfig represents the configuration used to create a new redis dialer.

func DefaultDialConfig

func DefaultDialConfig() DialConfig

DefaultDialConfig provides a default configuration to create a new redis dialer by best effort.

type MockDialConfig

type MockDialConfig struct {
	RedisConn redis.Conn
}

func DefaultMockDialConfig

func DefaultMockDialConfig() MockDialConfig

type PoolConfig

type PoolConfig struct {
	// MaxIdle is the allowed maximum number of idle connections in the pool.
	MaxIdle int

	// MaxActive is the allowed maximum number of connections allocated by the
	// pool at a given time.  When zero, there is no limit on the number of
	// connections in the pool.
	MaxActive int

	// Close connections after remaining idle for this duration. If the value
	// is zero, then idle connections are not closed. Applications should set
	// the timeout to a value less than the server's timeout.
	IdleTimeout time.Duration

	// Dial is an application supplied function for creating and configuring a
	// redis connection on demand.
	Dial func() (redis.Conn, error)
}

PoolConfig represents the configuration used to create a new redis pool.

func DefaultPoolConfig

func DefaultPoolConfig() PoolConfig

DefaultPoolConfig provides a default configuration to create a new redis pool by best effort.

type Service

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

func New

func New(config Config) (*Service, error)

New creates a new storage service.

func (*Service) Boot

func (s *Service) Boot()

func (*Service) Exists

func (s *Service) Exists(key string) (bool, error)

func (*Service) ExistsInScoredSet

func (s *Service) ExistsInScoredSet(key, element string) (bool, error)

func (*Service) Get

func (s *Service) Get(key string) (string, error)

func (*Service) GetAllFromList

func (s *Service) GetAllFromList(key string) ([]string, error)

func (*Service) GetAllFromSet

func (s *Service) GetAllFromSet(key string) ([]string, error)

func (*Service) GetElementsByScore

func (s *Service) GetElementsByScore(key string, score float64, maxElements int) ([]string, error)

func (*Service) GetHighestScoredElements

func (s *Service) GetHighestScoredElements(key string, maxElements int) ([]string, error)

func (*Service) GetRandom

func (s *Service) GetRandom() (string, error)

func (*Service) GetRandomFromScoredSet

func (s *Service) GetRandomFromScoredSet(key string) (string, error)

func (*Service) GetRandomFromSet

func (s *Service) GetRandomFromSet(key string) (string, error)

func (*Service) GetScoreOfElement

func (s *Service) GetScoreOfElement(key, element string) (float64, error)

func (*Service) GetStringMap

func (s *Service) GetStringMap(key string) (map[string]string, error)

func (*Service) Increment

func (s *Service) Increment(key string, n float64) (float64, error)

func (*Service) IncrementScoredElement

func (s *Service) IncrementScoredElement(key, element string, n float64) (float64, error)

func (*Service) LengthOfList

func (s *Service) LengthOfList(key string) (int, error)

func (*Service) LengthOfScoredSet

func (s *Service) LengthOfScoredSet(key string) (int, error)

func (*Service) PopFromList

func (s *Service) PopFromList(key string) (string, error)

func (*Service) PushToList

func (s *Service) PushToList(key string, element string) error

func (*Service) PushToSet

func (s *Service) PushToSet(key string, element string) error

func (*Service) Remove

func (s *Service) Remove(key string) error

func (*Service) RemoveFromList

func (s *Service) RemoveFromList(key string, element string) error

func (*Service) RemoveFromSet

func (s *Service) RemoveFromSet(key string, element string) error

func (*Service) RemoveScoredElement

func (s *Service) RemoveScoredElement(key string, element string) error

func (*Service) Set

func (s *Service) Set(key, value string) error

func (*Service) SetElementByScore

func (s *Service) SetElementByScore(key, element string, score float64) error

func (*Service) SetStringMap

func (s *Service) SetStringMap(key string, stringMap map[string]string) error

func (*Service) Shutdown

func (s *Service) Shutdown()

func (*Service) TrimEndOfList

func (s *Service) TrimEndOfList(key string, maxElements int) error

func (*Service) WalkKeys

func (s *Service) WalkKeys(glob string, closer <-chan struct{}, cb func(key string) error) error

func (*Service) WalkScoredSet

func (s *Service) WalkScoredSet(key string, closer <-chan struct{}, cb func(element string, score float64) error) error

func (*Service) WalkSet

func (s *Service) WalkSet(key string, closer <-chan struct{}, cb func(element string) error) error

Jump to

Keyboard shortcuts

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