redislimiter

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package redislimiter is the Redis-backed sliding-window rate limiter over ratelimit.Limit buckets, shared by every replica. While Redis fails it limits in process instead.

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 sliding-window limiter using ZSETs, with an in-process fallback holding the same limits.

func New

func New(rdb redis.UniversalClient, limits map[string]ratelimit.Limit, prefix string) (*Limiter, error)

New builds a Redis sliding-window limiter whose keys live under prefix (the deployment namespace, #307): <prefix><key>:<bucket>.

func (*Limiter) Allow added in v1.1.0

func (l *Limiter) Allow(ctx context.Context, bucket, key string) ratelimit.Result

Allow decides in Redis. When Redis fails it decides in process with the same limits, logs once, and lets one request try Redis again after each backoff; the first success logs the recovery and shares the budgets again.

func (*Limiter) StartCleanup added in v1.1.0

func (l *Limiter) StartCleanup(ctx context.Context, interval time.Duration)

StartCleanup sweeps the fallback's idle buckets until ctx is cancelled.

Jump to

Keyboard shortcuts

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