ratelimit

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package ratelimit provides rate limiting functionality using Redis

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RateLimiter

type RateLimiter interface {
	// Allow checks if a request is allowed for the given key
	// Returns true if allowed, false if rate limited, and the retry-after duration
	Allow(ctx context.Context, key string, limit int, window time.Duration) (bool, time.Duration, error)
}

RateLimiter defines the interface for rate limiting

func NewRedisRateLimiter

func NewRedisRateLimiter(client *redis.Client) RateLimiter

NewRedisRateLimiter creates a new Redis-based rate limiter

type RedisRateLimiter

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

RedisRateLimiter implements rate limiting using Redis sorted sets

func (*RedisRateLimiter) Allow

func (r *RedisRateLimiter) Allow(
	ctx context.Context,
	key string,
	limit int,
	window time.Duration,
) (bool, time.Duration, error)

Allow implements the RateLimiter interface using a sliding window algorithm

Jump to

Keyboard shortcuts

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