The spring-boot-starter-data-redis dependency adds Spring Data Redis and the Lettuce client to a Spring Boot application and auto-configures a connection factory, RedisTemplate and StringRedisTemplate from your properties. It is the standard way to use Redis for caching, sessions, counters, pub/sub and other fast key-value data without writing connection handling yourself.
Lettuce is the default client. You can switch to Jedis by excluding Lettuce and adding Jedis. A separate spring-boot-starter-data-redis-reactive starter exists for the reactive API.
| Component | Role |
|---|---|
| Spring Data Redis | Templates, repositories, serializers, pub/sub and cache support |
| Lettuce | Default Redis client: thread-safe, supports cluster, Sentinel and reactive use |
| Auto-configuration | RedisConnectionFactory, RedisTemplate<Object, Object>, StringRedisTemplate |
No version is needed when you use the Spring Boot parent or BOM.
The spring.data.redis.* prefix applies to Spring Boot 3 and later. Before Spring Boot 3 the prefix was spring.redis.*, which is a common cause of ignored settings when you copy older tutorials. You can also give a full URL with spring.data.redis.url=redis://user:pass@host:6379.
For Lettuce connection pooling, add commons-pool2 to the classpath and set spring.data.redis.lettuce.pool.enabled=true. Pooling matters mainly for blocking or transactional use, because Lettuce shares one connection across threads for ordinary commands.
StringRedisTemplate stores keys and values as strings, which keeps data readable in redis-cli and portable between languages.
The expiry passed to set makes the key disappear automatically, and increment is atomic on the server.
The default RedisTemplate uses Java serialization, which is opaque and unsafe to deserialize from untrusted data. Define a template with JSON serialization instead:
The Jackson serializer class names changed in Spring Data Redis 4 with the move to Jackson 3, so confirm the class for your version in the reference documentation.
Redis is a common backend for @Cacheable. Add spring-boot-starter-cache, enable caching, and select Redis:
Always set a time-to-live. Without one, cached entries never expire and memory grows until Redis evicts keys or runs out.
@RedisHash for simple object storage (best for small, flat data).RedisMessageListenerContainer.StreamOperations.Lettuce. To use Jedis, exclude io.lettuce:lettuce-core from the starter, add redis.clients:jedis, and set spring.data.redis.client-type=jedis.
Most often the prefix: Spring Boot 3 and later use spring.data.redis.*, while older versions used spring.redis.*.
The default template uses Java serialization for keys. Use StringRedisTemplate or set a StringRedisSerializer for keys.
Yes. Configure spring.data.redis.cluster.nodes or spring.data.redis.sentinel.master and spring.data.redis.sentinel.nodes.
spring-boot-starter-data-redis gives you a Lettuce-based connection, templates, caching support and pub/sub with almost no configuration. Use spring.data.redis.* properties, prefer StringRedisTemplate or JSON serializers over Java serialization, and always set expiry times for cached data.