package redis_rate

Import Path
	github.com/go-redis/redis_rate/v9 (on go.dev)

Dependency Relation
	imports 5 packages, and imported by one package

Involved Source Files lua.go rate.go
Code Examples { ctx := context.Background() rdb := redis.NewClient(&redis.Options{ Addr: "localhost:6379", }) _ = rdb.FlushDB(ctx).Err() limiter := redis_rate.NewLimiter(rdb) res, err := limiter.Allow(ctx, "project:123", redis_rate.PerSecond(10)) if err != nil { panic(err) } fmt.Println("allowed", res.Allowed, "remaining", res.Remaining) }
Package-Level Type Names (total 4, in which 3 are exported)
/* sort exporteds by: | */
Burst int Period time.Duration Rate int ( T) IsZero() bool ( T) String() string T : expvar.Var T : fmt.Stringer T : gopkg.in/yaml.v2.IsZeroer func PerHour(rate int) Limit func PerMinute(rate int) Limit func PerSecond(rate int) Limit func Limiter.Allow(ctx context.Context, key string, limit Limit) (*Result, error) func Limiter.AllowAtMost(ctx context.Context, key string, limit Limit, n int) (*Result, error) func Limiter.AllowN(ctx context.Context, key string, limit Limit, n int) (*Result, error)
Limiter controls how frequently events are allowed to happen. Allow is a shortcut for AllowN(ctx, key, limit, 1). AllowAtMost reports whether at most n events may happen at time now. It returns number of allowed events that is less than or equal to n. AllowN reports whether n events may happen at time now. func NewLimiter(rdb rediser) *Limiter
Allowed is the number of events that may happen at time now. Limit is the limit that was used to obtain this result. Remaining is the maximum number of requests that could be permitted instantaneously for this key given the current state. For example, if a rate limiter allows 10 requests per second and has already received 6 requests for this key this second, Remaining would be 4. ResetAfter is the time until the RateLimiter returns to its initial state for a given key. For example, if a rate limiter manages requests per second and received one request 200ms ago, Reset would return 800ms. You can also think of this as the time until Limit and Remaining will be equal. RetryAfter is the time until the next request will be permitted. It should be -1 unless the rate limit has been exceeded. func Limiter.Allow(ctx context.Context, key string, limit Limit) (*Result, error) func Limiter.AllowAtMost(ctx context.Context, key string, limit Limit, n int) (*Result, error) func Limiter.AllowN(ctx context.Context, key string, limit Limit, n int) (*Result, error)
Package-Level Functions (total 6, in which 4 are exported)
NewLimiter returns a new Limiter.
Package-Level Variables (total 2, neither is exported)
Package-Level Constants (only one, which is unexported)