ratelimitlib

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 21, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package ratelimilib is for rate limit any strategy operations

As a quick start:

client, err := redislib.NewGORedisClient(redislib.GORedisConfig{URL: "redis://localhost:6379"}, nil)
if err != nil {
	panic(err)
}

limiter := ratelimitlib.NewSlideWindowRateLimiter(client, 5, 30 * time.Second)
t := time.Now().UnixNano()
count, err := limiter.Incr(context.Background(), "kenny", t)
if err != nil {
	panic(err)
}
fmt.Println(count)

Index

Constants

View Source
const SlideWindowIncrLuaScript = `` /* 437-byte string literal not displayed */

Variables

This section is empty.

Functions

This section is empty.

Types

type RateLimiter

type RateLimiter interface {
	Incr(ctx context.Context, bucketName string, lastTimestamp int64) (int64, error)
}

type SlideWindowRateLimiter

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

func NewSlideWindowRateLimiter

func NewSlideWindowRateLimiter(client *redislib.GORedisClient, capacity int64, interval time.Duration) *SlideWindowRateLimiter

func (*SlideWindowRateLimiter) Incr

func (s *SlideWindowRateLimiter) Incr(ctx context.Context, bucketName string, lastTimestamp int64) (int64, error)

Jump to

Keyboard shortcuts

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