1、引入依赖
org.springframework.boot spring-boot-starter-data-redis 1234 2、配置主机spring.redis.host=192.168.124.15
1
3、查看源码
4、配置类
@Configuration
public class MyRedisConfig {
@Bean
public RedisTemplate<Object, Employee> empRedisTemplate(RedisConnectionFactory redisConnectionFactory)
throws UnknownHostException {
RedisTemplate<Object, Employee> template = new RedisTemplate<>();
template.setConnectionFactory(redisConnectionFactory);
Jackson2JsonRedisSerializer serializer = new Jackson2JsonRedisSerializer<>(Employee.class);
template.setDefaultSerializer(serializer);
return template;
}
}
123456789101112
5、测试
@Autowired
RedisTemplate redisTemplate;
@Autowired
StringRedis