qiuzeliang
4/11/2018 - 8:36 AM

配置Redis

Redis存对象

@Configuration
public class RedisClusterConfig {

    @Bean
    public RedisTemplate<String, Task> taskTemplate(RedisConnectionFactory redisConnectionFactory) {
        RedisTemplate<String, Task> redisTemplate = new RedisTemplate<>();
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        redisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer<>(Task.class));
        redisTemplate.afterPropertiesSet();
        return redisTemplate;
    }
}