Crates.io | rate_limiter |
lib.rs | rate_limiter |
version | 0.1.0 |
source | src |
created_at | 2021-07-07 10:19:19.287941 |
updated_at | 2021-07-07 10:19:19.287941 |
description | A RateLimit library come from redis-cell |
homepage | https://github.com/yangcancai/rate_limiter |
repository | https://github.com/yangcancai/rate_limiter/ |
max_upload_size | |
id | 419855 |
size | 11,456 |
A RateLimit library come from redis-cell
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);