Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RateLimiter ¶
type RateLimiter struct { RedisPool *redis.Pool Limit uint64 BaseKey string Interval time.Duration FlushInterval time.Duration // Just in case we can't use multi (for example: https://github.com/twitter/twemproxy/blob/master/notes/redis.md) MultiSupport bool // contains filtered or unexported fields }
func New ¶
func New(redisPool *redis.Pool, baseKey string, limit uint64, interval time.Duration, flushInterval time.Duration) *RateLimiter
New returns an instance or RateLimiter, which isn't yet initialized
func (*RateLimiter) Flush ¶
func (rl *RateLimiter) Flush()
Flush increments the counter in Redis, and saves the new total value
func (*RateLimiter) Increment ¶
func (rl *RateLimiter) Increment()
Increment adds 1 to the local counter (doesn't get synced until Flush gets called)
func (*RateLimiter) Init ¶
func (rl *RateLimiter) Init() error
Init starts the ticker, which takes care of periodically flushing/syncing the counter
func (*RateLimiter) IsOverLimit ¶
func (rl *RateLimiter) IsOverLimit() bool
IsOverLimit checks if we are over the limit we have set
func (*RateLimiter) Stop ¶
func (rl *RateLimiter) Stop()
Stop terminates the ticker, and flushed the final count we had
Click to show internal directories.
Click to hide internal directories.