redis

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPool

func NewPool(cfg *Config) *redigo.Pool

NewPool returns a redis pool with the given configuration

Types

type Config

type Config struct {
	URL            *url.URL
	Password       string
	MaxIdle        int32
	MaxActive      int32
	ReadTimeout    time.Duration
	WriteTimeout   time.Duration
	KeepAlive      time.Duration
	SentinelMaster string
	Sentinels      []*url.URL
}

Config is the redis pool configuration

type Pool

type Pool interface {
	GetContext(context.Context) (redigo.Conn, error)
}

Pool abstracts a redigo connection pool for testability

type TokenLimiter

type TokenLimiter struct {
	// contains filtered or unexported fields
}

TokenLimiter is a redis-based rate limiter implementing the algorithm in https://redislabs.com/redis-best-practices/basic-rate-limiting/

func NewTokenLimiter

func NewTokenLimiter(log *zap.Logger, redisPool Pool, keyPrefix string, limitPerMinute uint64, getToken func(ctx context.Context) string) *TokenLimiter

NewTokenLimiter returns a new TokenLimiter

func (*TokenLimiter) Allow

func (l *TokenLimiter) Allow(ctx context.Context) bool

Allow consumes one limitable event from the token in the context

Jump to

Keyboard shortcuts

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