I'm using redis in one of my java apps and I'm serializing a list of objects to be stored in Redis. However, I noticed that using the RedisTemplate would use the JdkSerializationRedisSerializer. Instead, I'd like to use Jackson to serialize since I believe it is better for speed. How would I go about configuring my RedisTemplate to use Jackson instead?
For clarification, this is how I'm configuring my RedisTemplate:
@Override
protected RedisConfiguration getRedisConfiguration() {
return redisConfiguration;
}
@Bean
public RedisTemplate<String, Object> getRedisTemplate() {
RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(jedisConnectionFactory());
return template;
}
like this,
@Bean
public RedisTemplate<String, Object> getRedisTemplate() {
RedisTemplate<String, Object> template = new RedisTemplate<>();
Jackson2JsonRedisSerializer jrs = new Jackson2JsonRedisSerializer(String.class);
template.setKeySerializer(jrs);
template.setConnectionFactory(jedisConnectionFactory());
return template;
}
and, I suggest you read this document https://docs.spring.io/spring-data/data-redis/docs/current/reference/html/#redis:template
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With