redislimit

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package redislimit is a ratelimit.Limiter whose windows live in Redis, so every replica shares them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Limiter

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

Limiter is a Redis-backed fixed-window limiter.

func New

func New(c redis.UniversalClient, opts ...Option) *Limiter

New returns a limiter on c. Windows are aligned to the clock of the replica that charges them, so keep replica clocks in sync.

func (*Limiter) Allow

func (l *Limiter) Allow(ctx context.Context, key string, n, limit int64, window time.Duration) (ratelimit.Decision, error)

Allow charges n against key's current fixed window of the given size. If window is <= 0 or n is < 0, it returns a zero Decision and an error, as the memory limiter does. A Redis failure is returned as an error too.

func (*Limiter) Kind

func (l *Limiter) Kind() string

Kind returns the type of this limiter.

type Option

type Option func(*Limiter)

Option configures the limiter.

func WithClock

func WithClock(now func() time.Time) Option

WithClock replaces time.Now, for tests.

func WithPrefix

func WithPrefix(p string) Option

WithPrefix sets the key prefix (default "nexus:rl:").

Jump to

Keyboard shortcuts

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