RedisTemplate
- to play and auto-configure the Redis with your app
- no-code needed if only
String
values in your app
(class) (interface)
RedisAccessor ----------- RedisOperations
| this contains the
| interfaces, dummy contracts needed
| to interact with Redis
|
↓
(class)
RedisTemplate
- sample java code for using spring redis operations
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
@Bean
public RedisOperations<String, Aircraft>
redisOperations(RedisConnectionFactory factory) {
Jackson2JsonRedisSerializer<Aircraft> serializer =
new Jackson2JsonRedisSerializer<>(Aircraft.class);
RedisTemplate<String, Aircraft> template = new RedisTemplate<>();
template.setConnectionFactory(factory);
template.setDefaultSerializer(serializer);
template.setKeySerializer(new StringRedisSerializer());
return template;
}
- [todo] understand 3rd argument to
template
as to why a new key serializer needs to be passed in?