ratelimiter

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 5, 2024 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RateLimiter

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

func NewRateLimiter

func NewRateLimiter(client *redis.Redis, limit int) *RateLimiter

func (*RateLimiter) AllowByDayRange

func (r *RateLimiter) AllowByDayRange(key string) (bool, error)

AllowByDayRange 实现限制一天内的访问次数的逻辑

func (*RateLimiter) AllowByDuration

func (r *RateLimiter) AllowByDuration(key string, windowSec int) (bool, error)

AllowByDuration 实现限制一段时间内的访问次数的逻辑

func (*RateLimiter) AllowByTimeRange

func (r *RateLimiter) AllowByTimeRange(key string, startTime, endTime int64) (bool, error)

AllowByTimeRange 实现限制一个时间段内的访问次数的逻辑

Jump to

Keyboard shortcuts

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