ratelimiter

package
v0.0.0-...-0f89747 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2018 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package ratelimiter implements generic rate-limiting algorithms

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TokenBucketTake

func TokenBucketTake(rc util.Cmder, key string, interval time.Duration, maxTokens, toTake int64) (int64, error)

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.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL