go-redis / redis_rate

Rate limiting for go-redis
https://redis.uptrace.dev/guide/go-redis-rate-limiting.html
BSD 2-Clause "Simplified" License
844 stars 101 forks source link

Initialize the limit #100

Open liuuujr opened 5 months ago

liuuujr commented 5 months ago

There are three ways to initialize a "Limit", which are "PerSecond(rate int)", "PerMinute(rate int)", "PerHour(rate int)". But the Limit generated by these three functions,the values of its "Rate" and "Burst" fields are equal。So I'd like to create a few more functions that initialize the LIMIT, which can specify the "rate" field and the "burst" field separately。

func PerHourWithCapacity(rate int, capacity int) Limit {
    return Limit{
        Rate:   rate,
        Period: time.Hour,
        Burst:  capacity,
    }
}
tikhomirovv commented 4 months ago

@liuuujr

The Limit is public, so you can configure it in your code to suit any needs. I don't think it's possible (or necessary) to cover every single case in a package.