Package ratelimiter implements generic rate-limiting algorithms
TokenBucketTake implements a token bucket rate-limiting system. Each bucket (identified by key) starts with some amount of tokens (maxTokens) in it. Whenever some action is performed tokens are removed from the bucket (toTake). If there are not enough tokens in the bucket then the action is rate-limited.
Tokens which were taken out of the bucket more than the given Duration previously are automatically returned to the bucket. If a bucket has never been used (i.e. key doesn't exist in redis) it is considered to be full.
Returns the number of tokens left in the bucket after toTake is removed, or a negative value if none are available to be taken. An error is only returned if communication with the datastore fails.