Spring Data Redis
Plug Redis into your Spring application with minimal effort
Spring Data Redis integrates Redis with the Spring framework, letting you plug Redis into your Spring application with minimal effort. It works with the Lettuce and Jedis clients, so Spring applications can take advantage of those clients' connection features as well as Spring's own abstractions.
Requirements
The examples in this section use Spring Boot 4.1 with Spring Data Redis 4.1. Add the Spring Boot starter for Spring Data Redis to your project:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
The starter uses the Lettuce client by default. Spring Boot reads the connection settings from your application properties:
spring.data.redis.host=<your-redis-host>
spring.data.redis.port=6379
Spring Boot creates a RedisConnectionFactory and a StringRedisTemplate for you,
and the pages in this section build on them.
Recipes
The pages in this section describe recipes for using Redis from Spring Data Redis:
- Use Redis with the Spring cache abstraction shows how to use Redis as the storage for Spring's cache abstraction, including preloading a cache at startup.
- Use Redis data structures with Spring shows how to use
RedisTemplatewith Redis data structures, such as a sorted set for a leaderboard. - Publish and subscribe to messages with Spring shows how to send and receive Redis pub/sub messages.
- Process Redis streams with Spring shows how to add entries to a stream and consume them with a consumer group.
- Store sessions with Spring Session shows how to keep HTTP session data in Redis.
- Client-side geographic failover shows how to configure resilient connections that automatically fail over between Redis endpoints.