redis

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2022 License: MIT Imports: 9 Imported by: 3

README

Redis

A package that provides some commonly needed extras when working with Redis.

Pool

Create a pool of Redis connections.

Subscriber

Subscribe to a Redis key, writing any received messages to a channel.

License

The MIT License (MIT)

Copyright (c) 2020 Scott Barr

See LICENSE

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPool

func NewPool(uri *url.URL) *redigo.Pool

func NewPoolFromURL added in v1.0.0

func NewPoolFromURL(uri *url.URL) *redigo.Pool

func NewPoolWithBorrowFunc added in v0.0.4

func NewPoolWithBorrowFunc(u *url.URL, f BorrowFunc) *redigo.Pool

func NoopOnBorrow added in v0.0.4

func NoopOnBorrow(c redigo.Conn, t time.Time) error

func PingOnBorrow added in v0.0.4

func PingOnBorrow(c redigo.Conn, t time.Time) error

Types

type BorrowFunc added in v0.0.4

type BorrowFunc func(c redigo.Conn, t time.Time) error

func NewSamplingBorrow added in v0.0.4

func NewSamplingBorrow(mod float64) BorrowFunc

type LogWrapper

type LogWrapper struct {
	Logger *log.Logger
}

LogWrapper wraps a standard Logger to implement the Logger interface.

func NewLogWrapper

func NewLogWrapper() *LogWrapper

NewLogWrapper returns a new LogWrapper.

func (*LogWrapper) Error

func (l *LogWrapper) Error(ctx context.Context, format string, args ...interface{})

Error implements the Logger interface.

func (*LogWrapper) Info

func (l *LogWrapper) Info(ctx context.Context, format string, args ...interface{})

Info implements the Logger interface.

func (*LogWrapper) Warn

func (l *LogWrapper) Warn(ctx context.Context, format string, args ...interface{})

Warn implements the Logger interface.

type Logger

type Logger interface {
	Info(context.Context, string, ...interface{})
	Warn(context.Context, string, ...interface{})
	Error(context.Context, string, ...interface{})
}

Logger is a minimal interface for a logger

type Sender

type Sender interface {
	Send(string, ...interface{}) error
}

Sender is an interface that is compatible with the redis.Send(..) function.

type Subscriber

type Subscriber struct {
	Logger Logger
	// contains filtered or unexported fields
}

Subscriber subscribes to a Redis key, and writes receive messages to a channel.

func NewSubscriber

func NewSubscriber(logger Logger, pool *redigo.Pool, key string, out chan []byte) Subscriber

NewSubscriber creates a Subscriber that will use the provided redis.Pool to subscribe to the given key.

Any messages that are received by the Subscriber will be written to the channel.

func (*Subscriber) Run

func (s *Subscriber) Run(ctx context.Context) error

Run receives pubsub messages from Redis after establishing a connection.

When a valid message is received it is written to the channel.

Jump to

Keyboard shortcuts

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