Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/abo/rerate
redis-based rate counter and rate limiter
https://github.com/abo/rerate
rate-counter rate-limiter redis
Last synced: 3 months ago
JSON representation
redis-based rate counter and rate limiter
- Host: GitHub
- URL: https://github.com/abo/rerate
- Owner: abo
- License: mit
- Created: 2016-05-24T08:59:00.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-03-28T02:22:25.000Z (about 7 years ago)
- Last Synced: 2024-01-17T10:58:57.187Z (5 months ago)
- Topics: rate-counter, rate-limiter, redis
- Language: Go
- Homepage:
- Size: 43.9 KB
- Stars: 26
- Watchers: 4
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- awesome-go-cn - rerate
- awesome-go-zh - rerate
- awesome-go - rerate - Redis-based rate counter and rate limiter for Go. (Utilities / HTTP Clients)
- awesome-go-projects - rerate - Redis-based rate counter and rate limiter for Go. (Utilities / HTTP Clients)
- awesome-go - rerate - based rate counter and rate limiter for Go. | - | - | - | (Utilities / HTTP Clients)
- awesome-go-with-framework - rerate - Redis-based rate counter and rate limiter for Go. (Utilities / HTTP Clients)
- awesome-go - rerate - Redis-based rate counter and rate limiter for Go. (Utilities / HTTP Clients)
- awesome-go. - rerate - Redis-based rate counter and rate limiter for Go. (Utilities / Advanced Console UIs)
- awesome-go - rerate - Redis-based rate counter and rate limiter for Go. (Utilities / <span id="高级控制台用户界面-advanced-console-uis">高级控制台用户界面 Advanced Console UIs</span>)
- awesome-go-cn - rerate - 基于 Redis 的速率计数器和限速器 (实用工具 / 高级控制台界面)
- awesome-go - rerate - Redis-based rate counter and rate limiter for Go. (Utilities / HTTP Clients)
- awesome-Char - rerate - Redis-based rate counter and rate limiter for Go. (Utilities / HTTP Clients)
- awesome-reader - rerate - Redis-based rate counter and rate limiter for Go. (Utilities / HTTP Clients)
- awesome-go - rerate - Redis-based rate counter and rate limiter for Go. (Utilities / HTTP Clients)
- awesome-go-cn - rerate - based rate counter and rate limiter for Go.) (实用工具 / Advanced Console UIs)
- awesome-go - rerate - Redis-based rate counter and rate limiter for Go. (Utilities / Advanced Console UIs)
- awesome-go - rerate - Redis-based rate counter and rate limiter for Go. (Utilities / Advanced Console UIs)
- awesome-go-handwritten - rerate - Redis-based rate counter and rate limiter for Go. (Utilities / HTTP Clients)
- awesome-go - rerate - 基於 Redis 的速率計數器和限速器 (實用工具 / 高級控制台界面)
- awesome-go - rerate - Redis-based rate counter and rate limiter for Go. - :arrow_down:1 - :star:5 (Utilities / HTTP Clients)
- awesome-go2 - rerate - Redis-based rate counter and rate limiter for Go. (Utilities / Advanced Console UIs)
- awesome-go - rerate - Redis-based rate counter and rate limiter for Go. (Utilities / HTTP Clients)
- awesome-go - rerate - Redis-based rate counter and rate limiter for Go. (Utilities / Advanced Console UIs)
- awesome-go - rerate - Redis-based rate counter and rate limiter for Go. (Utilities / HTTP Clients)
- awesome-go-cn - rerate
- awesome-go-zh - rerate
- go-awesome-cn-star - rerate
- awesome-go - rerate - redis-based rate counter and rate limiter - ★ 11 (Utilities)
README
rerate
===========
[![Build Status](https://travis-ci.org/abo/rerate.svg?branch=master)](https://travis-ci.org/abo/rerate)
[![GoDoc](https://godoc.org/github.com/abo/rerate?status.svg)](https://godoc.org/github.com/abo/rerate)
[![Go Report Card](https://goreportcard.com/badge/github.com/abo/rerate)](https://goreportcard.com/report/github.com/abo/rerate)
[![Coverage Status](https://coveralls.io/repos/github/abo/rerate/badge.svg?branch=master)](https://coveralls.io/github/abo/rerate?branch=master)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 identifierTutorial
--------
```
package mainimport (
"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
-------------- [API Reference](http://godoc.org/github.com/abo/rerate)
- [Wiki](https://github.com/abo/rerate/wiki)Sample - Sparkline
------------------![](https://github.com/abo/rerate/raw/master/cmd/sparkline/sparkline.png)
```
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
------------
WELCOMELicense
-------rerate is available under the [The MIT License (MIT)](https://opensource.org/licenses/MIT).