Categorygithub.com/daqiancode/freqlimit
modulepackage
0.0.1
Repository: https://github.com/daqiancode/freqlimit.git
Documentation: pkg.go.dev

# README

freqlimit

A tiny library to limit the request frequency based on redis

Installation

go get github.com/daqiancode/freqlimit

Example

// add frequency limit for user/1
limit := freqlimit.NewFreqLimit(getRedisClient(), "user/1")
// add freq limit < 2 times/1 seconds
limit.AddLimit(1, 2)
// add freq limit < 100 times/60 seconds
limit.AddLimit(60, 100)

ok, err:= limit.Incr()
if err!=nil {
    return err
}
if !ok {
    return errors.New("exceed the request frequency")
}

# Functions

No description provided by the author

# Variables

No description provided by the author

# Structs

No description provided by the author
No description provided by the author