Usage
This guide shows you how to integrate Redis Cache Java into your Java application.
Spring Boot 3 Compatibility
Redis Cache Java is built primarily against Spring Boot 4. A Spring Boot 3 variant is published with a -spring-boot3 suffix (for example, redis-cache-core-spring-boot3).
When using the Boot 3 variant, you must override two managed versions in your build because Spring Boot 3.x’s BOM pins older Lettuce and Netty versions than Redis Cache Java requires:
ext['lettuce.version'] = '7.5.1.RELEASE'
ext['netty.version'] = '4.2.12.Final'
Without these overrides, you will see NoClassDefFoundError: io/lettuce/core/api/sync/RediSearchCommands (Lettuce too old) or NoClassDefFoundError: io/netty/channel/MultiThreadIoEventLoopGroup (Netty too old). Netty 4.2.x is binary-compatible with 4.1.x for the Spring Boot surface area.
For Maven, set the same properties in your <properties> block:
<properties>
<lettuce.version>7.5.1.RELEASE</lettuce.version>
<netty.version>4.2.12.Final</netty.version>
</properties>
Basic Setup
To use Redis Cache Java as a backing implementation, add RedisCacheManager to your configuration:
@Bean
public RedisCacheManager cacheManager(RedisClient client) {
return RedisCacheManager.create(client);
}
Then you can tag the methods in your application that you want to apply caching to.
Advanced Configuration
RedisCacheManager behavior can be configured with RedisCacheManagerBuilder, letting you set the default RedisCacheConfiguration and predefined caches.
RedisCacheManager cacheManager = RedisCacheManager.builder(client)
.defaults(RedisCacheConfiguration.defaultConfig())
.configuration("hashCache", RedisCacheConfiguration.defaultConfig().hash())
.configuration("jsonCache", RedisCacheConfiguration.defaultConfig().json())
.configuration("stringCache", RedisCacheConfiguration.defaultConfig().string())
.build();
As shown in the preceding example, RedisCacheManager allows custom configuration on a per-cache basis.
The behavior of RedisCache created by RedisCacheManager is defined with RedisCacheConfiguration.
Next Steps
-
Configuration - Learn about all configuration options
-
Features - Explore advanced features
-
Metrics - Set up monitoring