httprateredis

package module
v0.0.0-...-b9ea542 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2023 License: MIT Imports: 6 Imported by: 0

README

httprate-redis

Go Reference

httprate.LimitCounter implementation with Redis backend Uses rueidis under the hood

LICENSE

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRedisLimitCounter

func NewRedisLimitCounter(cfg *Config) (httprate.LimitCounter, error)

NewRedisLimitCounter returns a new redis-based LimitCounter.

func WithRedisLimitCounter

func WithRedisLimitCounter(cfg *Config) (httprate.Option, error)

WithRedisLimitCounter is middleware that can be fed to httprate. Example:

limiter := httprate.Limit(
	serverOptions.RequestLimit,
	serverOptions.RequestPeriod,
	httprate.WithKeyByRealIP(),
	httprateredis.WithRedisLimitCounter(
		&httprateredis.Config{
			Addresses: redisAddresses,
			Password:  redisPassword,
		},
	),
)

Types

type Config

type Config struct {
	// Addresses is a list of redis host/ports, delimited like so:
	// * []string{"127.0.0.1:6379"}
	Addresses []string `toml:"host"`
	// Password is the Redis password (if the cluster has one)
	Password string `toml:"password"`
	// DBIndex is the DB index to select
	DBIndex int `toml:"db_index"` // default 0
}

Config defines the config of httprate-redis

Jump to

Keyboard shortcuts

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