tower_rate_limit_fred/lib.rs
1//! ## Overview
2//! A Redis-backed rate-limiting middleware for Tower using [Fred](https://crates.io/fred).
3//!
4//! Rate limiting is based on the [GCRA](https://liliace.dev/posts/intuition-of-the-gcra),
5//! which allows one request every [`emission_interval`], with unused allowance accumulating up to [`capacity`] to allow bursts.
6//!
7//! ## Required permissions
8//! Besides the commands Fred internally calls for all connections,
9//! this crate additionally uses the following commands:
10//! - [`EVALSHA`](https://valkey.io/commands/evalsha/)
11//! - [`GET`](https://valkey.io/commands/get/)
12//! - [`SCRIPT LOAD`](https://valkey.io/commands/script-load/)
13//! - [`SET`](https://valkey.io/commands/set/)
14//! - [`TIME`](https://valkey.io/commands/time/)
15//!
16//! ## Limitations
17//! All of [Redis](https://redis.io/), [Valkey](https://valkey.io/), and [Redict](https://redict.io/) currently embed [Lua](https://www.lua.org/) 5.1.
18//! Until they upgrade it to 5.3 or later, integers are stored as doubles, which start losing precision beyond 2^53.
19//! This occurs if the rate limit resets after May 2057, which is possible (but strongly discouraged) with improperly high [`capacity`] and [`emission_interval`], combined with heavy traffic.
20//!
21//! [`emission_interval`]: RateLimitLayerBuilder::emission_interval
22//! [`capacity`]: RateLimitLayerBuilder::capacity
23//!
24//! ## Features
25//! Name | Default | Description
26//! ---|---|---
27//! tracing | | Enable tracing. Keys are recorded as `&str`s if valid UTF-8, or as raw `&[u8]` otherwise
28//!
29//! ## Example
30//! ```
31#![doc = include_str!("../examples/axum.rs")]
32//! ```
33mod config;
34mod future;
35mod key_resolver;
36mod layer;
37mod service;
38
39pub use key_resolver::*;
40pub use layer::*;