Documentation ¶
Index ¶
- Constants
- Variables
- func Conn() redis.Conn
- func Do(command string, args ...any) (reply any, err error)
- func DoCtx(ctx context.Context, command string, args ...any) (reply any, err error)
- func NewPool(poolOpt PoolOption, connOpts ...ConnectionOption) error
- type ConnectionOption
- func FromViper(v *viper.Viper) []ConnectionOption
- func WithAddress(address string) ConnectionOption
- func WithDialOpts(dialOpts ...redis.DialOption) ConnectionOption
- func WithIdleTimeout(idleTimeout int) ConnectionOption
- func WithMaxActive(maxActive int) ConnectionOption
- func WithMaxIdle(maxIdle int) ConnectionOption
- func WithNetwork(network string) ConnectionOption
- type MockConnectionOption
- type MockPool
- type MockPoolOption
- type Pool
- type PoolOption
Constants ¶
const (
NetworkTCP = "tcp"
)
Variables ¶
var ( // ErrRedisNotInitialised is returned when the redis connection pool is not initialised. ErrRedisNotInitialised = errors.New("redis connection pool not initialised") )
var Latency = promauto.NewHistogramVec( prometheus.HistogramOpts{ Name: "redis_latency", Help: "Duration of Redis queries", }, []string{"command"}, )
Latency is the duration of Redis queries.
Functions ¶
func NewPool ¶
func NewPool(poolOpt PoolOption, connOpts ...ConnectionOption) error
NewPool returns a new Pool.
Types ¶
type ConnectionOption ¶
type ConnectionOption func(r *pool)
func FromViper ¶
func FromViper(v *viper.Viper) []ConnectionOption
func WithAddress ¶
func WithAddress(address string) ConnectionOption
func WithDialOpts ¶
func WithDialOpts(dialOpts ...redis.DialOption) ConnectionOption
func WithIdleTimeout ¶
func WithIdleTimeout(idleTimeout int) ConnectionOption
func WithMaxActive ¶
func WithMaxActive(maxActive int) ConnectionOption
func WithMaxIdle ¶
func WithMaxIdle(maxIdle int) ConnectionOption
func WithNetwork ¶
func WithNetwork(network string) ConnectionOption
type MockConnectionOption ¶
MockConnectionOption is an autogenerated mock type for the ConnectionOption type
func NewMockConnectionOption ¶
func NewMockConnectionOption(t interface { mock.TestingT Cleanup(func()) }) *MockConnectionOption
NewMockConnectionOption creates a new instance of MockConnectionOption. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*MockConnectionOption) Execute ¶
func (_m *MockConnectionOption) Execute(r *pool)
Execute provides a mock function with given fields: r
type MockPool ¶
MockPool is an autogenerated mock type for the Pool type
func NewMockPool ¶
NewMockPool creates a new instance of MockPool. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
type MockPoolOption ¶
MockPoolOption is an autogenerated mock type for the PoolOption type
func NewMockPoolOption ¶
func NewMockPoolOption(t interface { mock.TestingT Cleanup(func()) }) *MockPoolOption
NewMockPoolOption creates a new instance of MockPoolOption. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*MockPoolOption) Execute ¶
func (_m *MockPoolOption) Execute(p Pool)
Execute provides a mock function with given fields: p
type Pool ¶
type Pool interface { // Do will send a command to the server and returns the received reply on a connection from the pool. Do(command string, args ...any) (reply any, err error) // DoCtx will send a command to the server with a context and returns the received reply on a connection from the pool. DoCtx(ctx context.Context, command string, args ...any) (reply any, err error) // Conn returns a redis connection from the pool. Conn() redis.Conn }
type PoolOption ¶
type PoolOption func(p Pool)
func WithDefaultPool ¶
func WithDefaultPool() PoolOption
func WithInitializedPool ¶
func WithInitializedPool(pool Pool) PoolOption