Documentation ¶
Overview ¶
Package ratelimiter provides a fast and simlpe library to set and check limits using redis backend.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Limiter ¶
type Limiter struct { Usage int // Last seen Counter/Usage StopBurst bool // Switch of the burst part (default is off/false) // contains filtered or unexported fields }
Limiter structure
func New ¶
func New(key string, limit int, period int, rediskey string, pool *redis.Pool, debug ...bool) (*Limiter, error)
New Limiter creation 'rediskey' can be empty, 'debug' parameter is optional
func (*Limiter) AllowBurst ¶
func (l *Limiter) AllowBurst()
AllowBurst sets the flag to swith off anti.burst algorythm
func (*Limiter) CheckLimit ¶
CheckLimit only checks if the limit was reached or not without slot reservation
func (*Limiter) NoBurst ¶
func (l *Limiter) NoBurst()
NoBurst sets the flag to use anti.burst algorythm
func (*Limiter) Reset ¶
Reset cleans in Redis used data and resets Limiter
func (*Limiter) TryAcquire ¶
TryAcquire is checking the existing limit and reserves one slot if it possible. return false in cases the limit is reached or some internal errors.
Click to show internal directories.
Click to hide internal directories.