Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct { Address string MaxRate int64 LockWaitDuration time.Duration WorkerTimeout time.Duration LockName string }
Options is used to contain config options for the limiter Address is the address of the redis server MaxRate is the concurrency limit LockWaitDuration is used as a duration for busy waiting on the lock key WorkerTimeout is used as the TTL for the worker key, this should be set longer than you expect your workers to take.
type RateLimit ¶
type RateLimit struct { Redis *redis.Client Opts Options }
RateLimit is the limiter object exposed to control concurrency
func NewRateLimit ¶
NewRateLimit is for setting up a new rate limiter with options
func (*RateLimit) Add ¶
Add is for telling wait group something is starting A lock using SetNX is created in redis based on the l.Opts.LockName The lock busy waits until its free and then acquires it LockWaitDuration should be set to something reasonable so the CPU isn't wasting cycles. Add handles generating the UUID for the lock set and also the lock keys that are given a TTL The return value should be stored so you can pass the uid to Done()