Skip to content
This repository has been archived by the owner on Jan 23, 2022. It is now read-only.
/ gcra-redis Public archive

a library for go-redis that implements the GCRA rate limit algorithm

License

Notifications You must be signed in to change notification settings

256dpi/gcra-redis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gcra

A library for go-redis that implements the GCRA rate limit algorithm.

This code is based on the Node.js implementation by Losant.

Example

// create redis client
client := redis.NewClient(&redis.Options{Addr: "localhost:6379"})

// create limiter
l := New(client)

// check limit
r, err := l.Check("user-1234", 100, 10, 1, time.Second)
if err != nil {
    panic(err)
}

fmt.Printf("%+v\n", r)

// check limit
r, err = l.Check("user-1234", 100, 10, 100, time.Second)
if err != nil {
    panic(err)
}

fmt.Printf("%+v\n", r)

// Output:
// {Limited:false Remaining:99 RetryIn:0s ResetIn:1s}
// {Limited:true Remaining:99 RetryIn:1s ResetIn:1s}

About

a library for go-redis that implements the GCRA rate limit algorithm

Resources

License

Stars

Watchers

Forks

Packages

No packages published