ratelimit

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package ratelimit provides a distributed token bucket rate limiter backed by Redis Lua scripts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// MaxTokens is the bucket capacity (burst size).
	MaxTokens int
	// RefillRate is the number of tokens added per second.
	RefillRate float64
}

Config configures a rate limit for a specific tier/queue.

type Limiter

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

Limiter is a distributed rate limiter using Redis token bucket.

func New

func New(rdb rueidis.Client, keyPrefix string) *Limiter

New creates a new distributed rate limiter.

func (*Limiter) Allow

func (l *Limiter) Allow(ctx context.Context, tier string, n int, cfg Config) (bool, error)

Allow checks if n tokens are available for the given tier. Returns true if the request is allowed, false if rate-limited.

Jump to

Keyboard shortcuts

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