1 unstable release
0.1.0 | Jul 7, 2021 |
---|
#109 in #rate-limiting
9KB
166 lines
rate_limiter
A RateLimit library come from redis-cell
Required
- rust
How it works
use rate_limiter::rate_limiter::Store;
use rate_limiter::RateLimiter;
use rate_limiter::rate_limiter::to_second;
let mut store = Store::new();
let mut rate_limiter = RateLimiter::new(&mut store);
let rs = rate_limiter.rate_limit("foo".to_string(),10,1,1,1).unwrap();
assert_eq!(rs.allowed, true);
assert_eq!(rs.remaining, 10);
assert_eq!(rs.limit, 11);
assert_eq!(to_second(rs.retry_after), -1);
assert_eq!(to_second(rs.reset_after), 1);
Reference
Dependencies
~0.6–1MB
~15K SLoC