Installation
Add the Spring Boot Redis Rate Limiter starter to your Maven or Gradle project. The starter includes auto-configuration that works out of the box with Spring Boot 3.x.Requirements
Before installing, ensure your project meets these requirements:Java 17+
Java 17 or higher is required
Spring Boot 3.x
Spring Boot 3.4.5 or compatible version
Redis
Redis instance accessible to your application
Add the dependency
Choose your build tool and add the appropriate dependency:The starter uses Spring Boot’s dependency management, so you don’t need to specify versions for transitive dependencies like Spring Data Redis or Lettuce.
Configure Redis connection
The starter requires a Redis connection. Configure it using standard Spring Boot Redis properties:Redis with authentication
If your Redis instance requires authentication:Redis Cluster or Sentinel
For Redis Cluster or Sentinel configurations, use the standard Spring Data Redis cluster or sentinel properties:application.yml
Run Redis locally with Docker
For local development, you can quickly start a Redis instance using Docker:Terminal
Optional configuration
The starter provides several configuration properties to customize behavior. All properties are optional and have sensible defaults:Configuration properties reference
| Property | Type | Default | Description |
|---|---|---|---|
ratelimiter.enabled | boolean | true | Master switch to enable or disable the rate limiter auto-configuration |
ratelimiter.redis-key-prefix | string | ratelimiter | Prefix used for all Redis bucket keys |
ratelimiter.fail-open | boolean | false | When true, allows requests if Redis is unavailable (fail-open). When false, rejects requests if Redis is unavailable (fail-closed) |
ratelimiter.include-http-headers | boolean | true | When true, includes Retry-After and RateLimit-* headers in HTTP 429 responses |
ratelimiter.metrics-enabled | boolean | true | When true, records Micrometer metrics for rate limiter operations |
Verify installation
After adding the dependency and configuring Redis, start your Spring Boot application. You should see log messages indicating the rate limiter auto-configuration has activated:Console output
Check Redis connectivity
Ensure your application can connect to Redis. Check the logs for any connection errors.
Add a test annotation
Add
@RateLimit to a test controller or service method to verify the starter is working.Dependency tree
The starter includes these main dependencies:spring-boot-autoconfigure- Auto-configuration supportspring-context- Spring IoC containerspring-aop- AOP interceptor supportspring-web- HTTP exception handlingspring-data-redis- Redis operationslettuce-core- Redis clientmicrometer-core- Metrics recording
All dependencies are included automatically when you add the starter. You don’t need to add them individually.
What’s next
Quick start
Follow the step-by-step guide to implement rate limiting in your application
Back to introduction
Return to the introduction page