@upstash/ratelimit 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -87,6 +87,7 @@ import { Redis } from "@upstash/redis";
|
|
|
87
87
|
const ratelimit = new Ratelimit({
|
|
88
88
|
redis: Redis.fromEnv(),
|
|
89
89
|
limiter: Ratelimit.slidingWindow(10, "10 s"),
|
|
90
|
+
analytics: true
|
|
90
91
|
});
|
|
91
92
|
|
|
92
93
|
// Use a constant string to limit all requests with a single ratelimit
|
|
@@ -161,6 +162,7 @@ const ratelimit = new Ratelimit({
|
|
|
161
162
|
redis: Redis.fromEnv(),
|
|
162
163
|
limiter: Ratelimit.slidingWindow(10, "10 s"),
|
|
163
164
|
timeout: 1000, // 1 second
|
|
165
|
+
analytics: true
|
|
164
166
|
});
|
|
165
167
|
```
|
|
166
168
|
|
|
@@ -184,6 +186,7 @@ in a finite amount of time.
|
|
|
184
186
|
const ratelimit = new Ratelimit({
|
|
185
187
|
redis: Redis.fromEnv(),
|
|
186
188
|
limiter: Ratelimit.slidingWindow(10, "10 s"),
|
|
189
|
+
analytics: true
|
|
187
190
|
});
|
|
188
191
|
|
|
189
192
|
// `blockUntilReady` returns a promise that resolves as soon as the request is allowed to be processed, or after 30 seconds
|
|
@@ -259,6 +262,7 @@ const ratelimit = new MultiRegionRatelimit({
|
|
|
259
262
|
}),
|
|
260
263
|
],
|
|
261
264
|
limiter: MultiRegionRatelimit.slidingWindow(10, "10 s"),
|
|
265
|
+
analytics: true
|
|
262
266
|
});
|
|
263
267
|
|
|
264
268
|
// Use a constant string to limit all requests with a single ratelimit
|
|
@@ -326,6 +330,7 @@ Create a new ratelimiter, that allows 10 requests per 10 seconds.
|
|
|
326
330
|
const ratelimit = new Ratelimit({
|
|
327
331
|
redis: Redis.fromEnv(),
|
|
328
332
|
limiter: Ratelimit.fixedWindow(10, "10 s"),
|
|
333
|
+
analytics: true
|
|
329
334
|
});
|
|
330
335
|
```
|
|
331
336
|
|
|
@@ -366,6 +371,7 @@ Create a new ratelimiter, that allows 10 requests per 10 seconds.
|
|
|
366
371
|
const ratelimit = new Ratelimit({
|
|
367
372
|
redis: Redis.fromEnv(),
|
|
368
373
|
limiter: Ratelimit.slidingWindow(10, "10 s"),
|
|
374
|
+
analytics: true
|
|
369
375
|
});
|
|
370
376
|
```
|
|
371
377
|
|
|
@@ -397,9 +403,30 @@ size of 10.
|
|
|
397
403
|
const ratelimit = new Ratelimit({
|
|
398
404
|
redis: Redis.fromEnv(),
|
|
399
405
|
limiter: Ratelimit.tokenBucket(5, "10 s", 10),
|
|
406
|
+
analytics: true
|
|
400
407
|
});
|
|
401
408
|
```
|
|
402
409
|
|
|
410
|
+
## Analytics
|
|
411
|
+
|
|
412
|
+
You can enable analytics to get a better understanding of how your ratelimiting
|
|
413
|
+
is performing. This is done by setting `analytics: true` in the options.
|
|
414
|
+
|
|
415
|
+
All data is stored in the same Redis database.
|
|
416
|
+
|
|
417
|
+
```ts
|
|
418
|
+
const ratelimit = new Ratelimit({
|
|
419
|
+
redis: Redis.fromEnv(),
|
|
420
|
+
limiter: Ratelimit.tokenBucket(5, "10 s", 10),
|
|
421
|
+
analytics: true // <- Enable analytics
|
|
422
|
+
});
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
Go to the [Ratelimit Dashboard](https://console.upstash.com/rate-limit) and select the database you are using.
|
|
426
|
+
|
|
427
|
+

|
|
428
|
+
|
|
429
|
+
|
|
403
430
|
## Contributing
|
|
404
431
|
|
|
405
432
|
### [Install Deno](https://deno.land/#installation)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@upstash/ratelimit",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"typescript": "^4.9.4"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@upstash/core-analytics": "0.0.
|
|
37
|
+
"@upstash/core-analytics": "0.0.1"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "tsup",
|