Created
August 6, 2024 22:57
-
-
Save skeptrunedev/edfea90bb0ecfe5fc00872bc81e29452 to your computer and use it in GitHub Desktop.
Rust actix-web implementation for actix-extensible-rate-limit crate (Trieve)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| redis = { version = "0.25", features = [ | |
| "tokio-rustls-comp", | |
| "aio", | |
| "connection-manager", | |
| ] } | |
| actix-extensible-rate-limit = { version = "0.3.1", features = ["redis"] } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use actix_extensible_rate_limit::backend::redis::RedisBackend; | |
| use actix_identity::IdentityMiddleware; | |
| let redis_rate_limit_client = redis::Client::open("redis://127.0.0.1/").unwrap(); | |
| let redis_rate_limit_manager = redis::aio::ConnectionManager::new(redis_rate_limit_client).await.unwrap(); | |
| let backend = RedisBackend::builder(redis_rate_limit_manager).build(); | |
| let input = SimpleInputFunctionBuilder::new(Duration::from_secs(60), 5) | |
| .real_ip_key() | |
| .build(); | |
| let middleware = RateLimiter::builder(backend.clone(), input) | |
| .add_headers() | |
| .build(); | |
| App::new().wrap(middleware) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment