redis

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2021 License: MIT Imports: 15 Imported by: 1

Documentation

Index

Constants

View Source
const DefaultProviderName = "redis"

DefaultProviderName is default provider name

Variables

This section is empty.

Functions

func Get

func Get(ctx context.Context) (cache.Provider, error)

func GetEnity

func GetEnity(ctx context.Context, enityName string) (interface{}, error)

func Registrate

func Registrate(ctx context.Context) (context.Context, error)

func RegistrateEnity

func RegistrateEnity(ctx context.Context, enityName string, options interface{}) (context.Context, error)

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) Options added in v0.2.0

func (c *Config) Options() (*redis.Options, error)

func (*Config) SetDefault added in v0.3.0

func (c *Config) SetDefault() *Config

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 GetEnityTypeCast(ctx context.Context, enityName string) (*Enity, error)

func NewEnity

func NewEnity(ctx context.Context, name string, cfg interface{}) (*Enity, error)

NewEnity create new enity.

func (*Enity) Clear

func (c *Enity) Clear() error

Clear clear all items from selected connection.

func (*Enity) Delete

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

Delete item from cache by key.

func (*Enity) Get

func (c *Enity) Get(key string, value interface{}) error

Get item from cache by key.

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) JSONGet

func (c *Enity) JSONGet(key, path string, value interface{}) error

JSONGet item from cache by key.

func (*Enity) JSONSet

func (c *Enity) JSONSet(key, path, json string) error

JSONSet item in cache by key.

func (*Enity) JSONSetNX

func (c *Enity) JSONSetNX(key, path, json string) error

JSONSetNX item in cache by key.

func (*Enity) NewMutex

func (c *Enity) NewMutex(expire, checkInterval time.Duration) (*Mutex, error)

NewMutex create new redis mutex

func (*Enity) NewMutexByID

func (c *Enity) NewMutexByID(lockID string, expire, checkInterval time.Duration) (*Mutex, error)

NewMutexByID create new redis mutex with selected id

func (*Enity) Set

func (c *Enity) Set(key string, value interface{}) error

Set item in cache by key.

func (*Enity) SetConnPoolLifetime

func (c *Enity) SetConnPoolLifetime(connMaxLifetime time.Duration)

SetConnPoolLifetime sets connection lifetime.

func (*Enity) SetConnPoolLimits

func (c *Enity) SetConnPoolLimits(minIdleConnections, maxOpenedConnections int)

SetConnPoolLimits sets pool limits for connections counts.

func (*Enity) SetNX

func (c *Enity) SetNX(key string, value interface{}) error

SetNX (Not eXist) item in cache by key.

func (*Enity) SetPoolLimits

func (c *Enity) SetPoolLimits(maxIdleConnections, maxOpenedConnections int, connMaxLifetime time.Duration)

SetPoolLimits sets connection pool limits.

func (*Enity) Shutdown

func (c *Enity) Shutdown() error

Shutdown shutdowns queue worker and connection watcher. Later will also close connection to database. This is a blocking call.

func (*Enity) Size

func (c *Enity) Size() int

Size return count of item in cache

func (*Enity) Start

func (c *Enity) Start() error

Start starts connection workers and connection procedure itself.

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 NewMutex

func NewMutex(conn *rejson.Client, expire, checkInterval time.Duration) (*Mutex, error)

NewMutex creates new distributed redis mutex

func NewMutexByID

func NewMutexByID(conn *rejson.Client, lockKey string, expire, checkInterval time.Duration) (*Mutex, error)

NewMutexByID creates new distributed redis mutex by ID

func (*Mutex) Extend

func (m *Mutex) Extend(timeout time.Duration) (err error)

Extend attempts to extend the timeout of a Redis-lock.

func (*Mutex) Lock

func (m *Mutex) Lock() (err error)

Lock sets Redis-lock item. It is blocking call which will wait until redis lock key will be deleted, pretty much like simple mutex.

func (*Mutex) Unlock

func (m *Mutex) Unlock() (err error)

Unlock deletes Redis-lock item.

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

func NewProvider(ctx context.Context) *Provider

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) Clear

func (p *Provider) Clear(connectionName string) error

Clear clear all items from selected connection.

func (*Provider) ClearAll added in v0.3.0

func (p *Provider) ClearAll() error

ClearAll clear all items from all connections.

func (*Provider) CreateEnity

func (p *Provider) CreateEnity(enityName string, options interface{}) error

CreateEnity should create enity using passed parameters.

func (*Provider) Delete

func (p *Provider) Delete(connectionName, key string) error

Delete item from cache by key.

func (*Provider) Get

func (p *Provider) Get(connectionName, key string, value interface{}) error

Get item from cache by key.

func (*Provider) GetEnity

func (p *Provider) GetEnity(connectionName string) (interface{}, error)

GetEnity should return pointer to connection structure to caller.

func (*Provider) Set

func (p *Provider) Set(connectionName, key string, value interface{}) error

Set item in cache by key.

func (*Provider) SetNX

func (p *Provider) SetNX(connectionName, key string, value interface{}) error

SetNX (Not eXist) item in cache by key.

Jump to

Keyboard shortcuts

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