Documentation ¶
Index ¶
- Constants
- func Get(ctx context.Context) (cache.Provider, error)
- func GetEnity(ctx context.Context, enityName string) (interface{}, error)
- func Registrate(ctx context.Context) (context.Context, error)
- func RegistrateEnity(ctx context.Context, enityName string, options interface{}) (context.Context, error)
- type Config
- type Enity
- func (c *Enity) Clear() error
- func (c *Enity) Delete(key string) error
- func (c *Enity) Get(key string, value interface{}) error
- func (c *Enity) GetMetrics(prefix string) stats.MapMetricsOptions
- func (c *Enity) GetReadyHandlers(prefix string) stats.MapCheckFunc
- func (c *Enity) JSONGet(key, path string, value interface{}) error
- func (c *Enity) JSONSet(key, path, json string) error
- func (c *Enity) JSONSetNX(key, path, json string) error
- func (c *Enity) NewMutex(expire, checkInterval time.Duration) (*Mutex, error)
- func (c *Enity) NewMutexByID(lockID string, expire, checkInterval time.Duration) (*Mutex, error)
- func (c *Enity) Set(key string, value interface{}) error
- func (c *Enity) SetConnPoolLifetime(connMaxLifetime time.Duration)
- func (c *Enity) SetConnPoolLimits(minIdleConnections, maxOpenedConnections int)
- func (c *Enity) SetNX(key string, value interface{}) error
- func (c *Enity) SetPoolLimits(maxIdleConnections, maxOpenedConnections int, connMaxLifetime time.Duration)
- func (c *Enity) Shutdown() error
- func (c *Enity) Size() int
- func (c *Enity) Start() error
- func (c *Enity) WaitForEstablishing()
- type Mutex
- type Provider
- func (p *Provider) Clear(connectionName string) error
- func (p *Provider) ClearAll() error
- func (p *Provider) CreateEnity(enityName string, options interface{}) error
- func (p *Provider) Delete(connectionName, key string) error
- func (p *Provider) Get(connectionName, key string, value interface{}) error
- func (p *Provider) GetEnity(connectionName string) (interface{}, error)
- func (p *Provider) Set(connectionName, key string, value interface{}) error
- func (p *Provider) SetNX(connectionName, key string, value interface{}) error
Constants ¶
const DefaultProviderName = "redis"
DefaultProviderName is default provider name
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶ added in v0.2.0
type Config struct { // DSN is a connection string in form of DSN. Example: // redis://user:password@host:port/databaseNumber. // Default: "redis://rd:rd@localhost:6379" DSN string `envconfig:"optional"` // MaxConnectionLifetime specifies maximum connection lifetime // for reusage. Default: 10 seconds. MaxConnectionLifetime time.Duration `envconfig:"optional"` // Minimum number of idle connections which is useful when establishing // new connection is slow. Default: 10 connections. MinIdleConnections int `envconfig:"optional"` // MaxOpenedConnections specify upper limit for opened connections // count. Default: 30 connections. MaxOpenedConnections int `envconfig:"optional"` // StartWatcher indicates to connection controller that it should // also start asynchronous connection watcher. StartWatcher bool `envconfig:"optional"` // Timeout is a timeout in seconds for connection checking. Every // this count of seconds redis connection will be checked for // aliveness and, if it dies, attempt to reestablish connection // will be made. Default timeout is 10 seconds. Timeout time.Duration `envconfig:"optional"` // KeyPrefix is a prefix for eache key in redis KeyPrefix string `envconfig:"optional"` // ClearTime is a time of live item ClearTime time.Duration `envconfig:"optional"` }
Config represents configuration structure for every connection.
func (*Config) SetDefault ¶ added in v0.3.0
SetDefault checks connection options. If required field is empty - it will be filled with some default value.
type Enity ¶
type Enity struct { // Metrics stats.Service Conn *rejson.Client // contains filtered or unexported fields }
Enity is a connection controlling structure. It controls connection, asynchronous queue and everything that related to specified connection.
func GetEnityTypeCast ¶
func (*Enity) GetMetrics ¶
func (c *Enity) GetMetrics(prefix string) stats.MapMetricsOptions
GetMetrics return map of the metrics from cache connection
func (*Enity) GetReadyHandlers ¶
func (c *Enity) GetReadyHandlers(prefix string) stats.MapCheckFunc
GetReadyHandlers return array of the readyHandlers from database connection
func (*Enity) NewMutexByID ¶
NewMutexByID create new redis mutex with selected id
func (*Enity) SetConnPoolLifetime ¶
SetConnPoolLifetime sets connection lifetime.
func (*Enity) SetConnPoolLimits ¶
SetConnPoolLimits sets pool limits for connections counts.
func (*Enity) SetPoolLimits ¶
func (c *Enity) SetPoolLimits(maxIdleConnections, maxOpenedConnections int, connMaxLifetime time.Duration)
SetPoolLimits sets connection pool limits.
func (*Enity) Shutdown ¶
Shutdown shutdowns queue worker and connection watcher. Later will also close connection to database. This is a blocking call.
func (*Enity) WaitForEstablishing ¶
func (c *Enity) WaitForEstablishing()
WaitForEstablishing will block execution until connection will be successfully established.
type Mutex ¶
type Mutex struct {
// contains filtered or unexported fields
}
Mutex provides a distributed mutex across multiple instances via Redis
func NewMutexByID ¶
func NewMutexByID(conn *rejson.Client, lockKey string, expire, checkInterval time.Duration) (*Mutex, error)
NewMutexByID creates new distributed redis mutex by ID
type Provider ¶
type Provider struct {
*providerwithmetrics.Provider
}
Provider provides Redis database worker. This provider supports asynchronous database actions (like bulk inserting). Every connection will have own goroutine for queue processing.
func NewProvider ¶
Initialize should initialize provider. If asynchronous mode supported by provider (e.g. for batch inserting using transactions) queue processor should also be started here.
func (*Provider) CreateEnity ¶
CreateEnity should create enity using passed parameters.