Skip to content
forked from abo/rerate

redis-based rate counter and rate limiter

License

Notifications You must be signed in to change notification settings

iandouglas/rerate

 
 

Repository files navigation

Go Rate Limiting with Redis

Adapted heavily from github.com/abo/rerate but uses gopkg.in/redis.v5 as its Redis client.

All interfaces should stay the same as rerate, so in theory this should be a drop-in replacement.

If you have trouble implementing this library, contact me at ian@getstream.io for support.

No warranty expressed or implied with this library, and I don't guarantee we'll be very fast at merging in changes from rerate in the future.


Old Documentation

rerate

Build Status GoDoc Go Report Card Coverage Status

rerate is a redis-based ratecounter and ratelimiter

  • Dead simple api
  • With redis as backend, multiple rate counters/limiters can work as a cluster
  • Count/Limit requests any period, 2 day, 1 hour, 5 minute or 2 second, it's up to you
  • Recording requests as a histotram, which can be used to visualize or monitor
  • Limit requests from single ip, userid, applicationid, or any other unique identifier

Tutorial

package main

import (
    "github.com/abo/rerate"
)

...

func main() {
    pool := newRedisPool("localhost:6379", "")

    // Counter
    counter := rerate.NewCounter(pool, "rl:test", 10 * time.Minute, 15 * time.Second)
    counter.Inc("click")
    c, err := counter.Count("click")

    // Limiter
    limiter := rerate.NewLimiter(pool, "rl:test", 1 * time.Hour, 15 * time.Minute, 100)
    limiter.Inc("114.255.86.200")
    rem, err := limiter.Remaining("114.255.86.200")
    exceed, err := limiter.Exceeded("114.255.86.200")
}

Installation

Install rerate using the "go get" command:

go get github.com/abo/rerate

Documentation

Contributing

WELCOME

License

rerate is available under the The MIT License (MIT).

About

redis-based rate counter and rate limiter

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%