limiters

package
v0.0.0-...-476b611 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KeyRateLimiter

type KeyRateLimiter struct {
	// contains filtered or unexported fields
}

func NewKeyRateLimiter

func NewKeyRateLimiter(ctx context.Context, cache *redis.Cache, name string, amount int64, every time.Duration) *KeyRateLimiter

NewKeyRateLimiter creates a new rate limiter that will limit to `amount` operations `every` duration. The name will be used to uniquely identify this limiter in the specified redis cache. Consequently, two different limiters in the same cache should NOT have the same name. It is safe to share a single KeyRateLimiter object among multiple consumers to share a limit.

func (*KeyRateLimiter) ForKey

func (i *KeyRateLimiter) ForKey(ctx context.Context, key string) (bool, time.Duration, error)

ForKey will check if the given key has exceeded the rate limit for this named limiter

func (*KeyRateLimiter) Name

func (i *KeyRateLimiter) Name() string

Name returns the name of this limiter

func (*KeyRateLimiter) Reset

func (i *KeyRateLimiter) Reset(ctx context.Context, key string) error

Reset resets the limit of a key

Jump to

Keyboard shortcuts

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