Home

Awesome

rerate

Build Status GoDoc Go Report Card Coverage Status

rerate is a redis-based ratecounter and ratelimiter

Tutorial

package main

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

...

func main() {
    // redigo buckets
    pool := newRedisPool("localhost:6379", "")
    buckets := rerate.NewRedigoBuckets(pool)

    // OR redis buckets
    // client := redis.NewClient(&redis.Options{
	//	 Addr:     "localhost:6379",
	// 	 Password: "",
	// 	 DB:       0,
	// })
    // buckets := rerate.NewRedisBuckets(client)
    
    // Counter
    counter := rerate.NewCounter(buckets, "rl:test", 10 * time.Minute, 15 * time.Second)
    counter.Inc("click")
    c, err := counter.Count("click")
    
    // Limiter
    limiter := rerate.NewLimiter(buckets, "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

Sample - Sparkline

    cd cmd/sparkline
    npm install webpack -g
    npm install
    webpack && go run main.go

Open http://localhost:8080 in Browser, And then move mouse.

Contributing

WELCOME

License

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