Skip to content

A distributed rate limiter, based on redis/lua and token-bucket algorithm.

Notifications You must be signed in to change notification settings

day-dreams/ratelimiter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ratelimiter

A distributed rate limiter, based on redis/lua and token-bucket algorithm.

see usage example

    import 	(
        "github.com/go-redis/redis"
        "github.com/day-dreams/ratelimiter"
    )

    // initialize a ratelimiter by redis client
    client := redis.NewClient(&redis.Options{Addr: "127.0.0.1:6379"})
    limiter, err := ratelimiter.New(client, 50, 50, 10)
    if err != nil {
        panic(err)
    }
    // try to get 5 tickets
    ok, err := limiter.Get(context.TODO(), "YourUserID", 5)
    if err == nil && ok {
        fmt.Printf("you got your ticket!\n")
    }

demo

About

A distributed rate limiter, based on redis/lua and token-bucket algorithm.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages