Skip to content

Commit 7569e0e

Browse files
committed
Cleanup
1 parent 95dbe54 commit 7569e0e

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
semi: false
2+
singleQuote: true
3+
proseWrap: always
4+
printWidth: 100

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
dist: xenial
2-
sudo: false
32
language: go
43

54
services:
65
- redis-server
76

87
go:
9-
- 1.11.x
108
- 1.12.x
119
- 1.13.x
10+
- 1.14.x
1211
- tip
1312

1413
matrix:
@@ -21,4 +20,5 @@ env:
2120
go_import_path: github.com/go-redis/redis_rate
2221

2322
before_install:
24-
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.21.0
23+
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go
24+
env GOPATH)/bin v1.21.0

README.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,57 @@
11
# Rate limiting for go-redis
22

33
[![Build Status](https://travis-ci.org/go-redis/redis_rate.svg?branch=master)](https://travis-ci.org/go-redis/redis_rate)
4-
[![GoDoc](https://godoc.org/github.com/go-redis/redis_rate?status.svg)](https://godoc.org/github.com/go-redis/redis_rate)
4+
[![GoDoc](https://godoc.org/github.com/go-redis/redis_rate?status.svg)](https://pkg.go.dev/github.com/go-redis/redis_rate/v9)
55

6-
This package is based on [rwz/redis-gcra](https://github.com/rwz/redis-gcra) and implements [GCRA](https://en.wikipedia.org/wiki/Generic_cell_rate_algorithm) (aka leaky bucket) for rate limiting based on Redis. The code requires Redis version 3.2 or newer since it relies on [replicate_commands](https://redis.io/commands/eval#replicating-commands-instead-of-scripts) feature.
6+
This package is based on [rwz/redis-gcra](https://github.com/rwz/redis-gcra) and implements
7+
[GCRA](https://en.wikipedia.org/wiki/Generic_cell_rate_algorithm) (aka leaky bucket) for rate
8+
limiting based on Redis. The code requires Redis version 3.2 or newer since it relies on
9+
[replicate_commands](https://redis.io/commands/eval#replicating-commands-instead-of-scripts)
10+
feature.
711

812
## Installation
913

10-
redis_rate requires a Go version with [Modules](https://github.com/golang/go/wiki/Modules) support and uses import versioning. So please make sure to initialize a Go module before installing redis_rate:
14+
redis_rate requires a Go version with [Modules](https://github.com/golang/go/wiki/Modules) support
15+
and uses import versioning. So please make sure to initialize a Go module before installing
16+
redis_rate:
1117

12-
``` shell
18+
```shell
1319
go mod init github.com/my/repo
1420
go get github.com/go-redis/redis_rate/v8
1521
```
1622

1723
Import:
1824

19-
``` go
25+
```go
2026
import "github.com/go-redis/redis_rate/v8"
2127
```
2228

2329
## Example
2430

25-
``` go
31+
```go
2632
package redis_rate_test
2733

2834
import (
35+
"context"
2936
"fmt"
3037

31-
"github.com/go-redis/redis/v7"
32-
"github.com/go-redis/redis_rate/v8"
38+
"github.com/go-redis/redis/v8"
39+
"github.com/go-redis/redis_rate/v9"
3340
)
3441

3542
func ExampleNewLimiter() {
43+
ctx := context.Background()
3644
rdb := redis.NewClient(&redis.Options{
3745
Addr: "localhost:6379",
3846
})
39-
_ = rdb.FlushDB().Err()
47+
_ = rdb.FlushDB(ctx).Err()
4048

4149
limiter := redis_rate.NewLimiter(rdb)
42-
res, err := limiter.Allow("project:123", redis_rate.PerSecond(10))
50+
res, err := limiter.Allow(ctx, "project:123", redis_rate.PerSecond(10))
4351
if err != nil {
4452
panic(err)
4553
}
46-
fmt.Println(res.Allowed, res.Remaining)
47-
// Output: true 9
54+
fmt.Println("allowed", res.Allowed, "remaining", res.Remaining)
55+
// Output: allowed 1 remaining 9
4856
}
4957
```

rate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ type Result struct {
148148
// Limit is the limit that was used to obtain this result.
149149
Limit *Limit
150150

151-
// Allowed reports whether event may happen at time now.
151+
// Allowed is the number of events that may happen at time now.
152152
Allowed int
153153

154154
// Remaining is the maximum number of requests that could be

0 commit comments

Comments
 (0)