redisconn

package
v0.0.0-...-35d8de9 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package redisconn is a facade for Redis connection pool.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotConfigured = errors.New("Redis connection pool is not configured")

ErrNotConfigured is returned by Get if the context has no Redis pool inside.

Functions

func Get

func Get(ctx context.Context) (redis.Conn, error)

Get returns a Redis connection using the pool installed in the context.

May block until such connection is available. Returns an error if the context expires before that. The returned connection itself is not associated with the context and can outlive it.

The connection MUST be explicitly closed as soon as it's no longer needed, otherwise leaks and slow downs are eminent.

func GetPool

func GetPool(ctx context.Context) *redis.Pool

GetPool returns a connection pool in the context or nil if not there.

func NewPool

func NewPool(addr string) *redis.Pool

NewPool returns a new pool configured with default parameters.

"addr" is TCP "host:port" of a Redis server to connect to. No actual connection is established yet (this happens first time the pool is used).

Doesn't use any authentication or encryption.

func ReportStats

func ReportStats(ctx context.Context, pool *redis.Pool, name string)

ReportStats reports the connection pool stats as tsmon metrics.

For best results should be called once a minute or right before tsmon flush.

"name" is used as "pool" metric field, to distinguish pools between each other.

func UsePool

func UsePool(ctx context.Context, pool *redis.Pool) context.Context

UsePool installs a connection pool into the context, to be used by Get.

Types

This section is empty.

Jump to

Keyboard shortcuts

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