rate_limiter

Crates.iorate_limiter
lib.rsrate_limiter
version0.1.0
sourcesrc
created_at2021-07-07 10:19:19.287941
updated_at2021-07-07 10:19:19.287941
descriptionA RateLimit library come from redis-cell
homepagehttps://github.com/yangcancai/rate_limiter
repositoryhttps://github.com/yangcancai/rate_limiter/
max_upload_size
id419855
size11,456
Cam (yangcancai)

documentation

README

rate_limiter

A RateLimit library come from redis-cell CI

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

redis-cell rate-limiting

Commit count: 6

cargo fmt