>> 快速开始
- 创建springboot项目,引入redis pom依赖,如下:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
- 将所需的redis的Bean实例注入到IOC容器中
@Configuration
public class BootConfiguration {
@Bean
public RedisTemplate<Object,Object> redisTemplate(RedisConnectionFactory redisConnectionFactory){
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(redisConnectionFactory);
return redisTemplate;
}
}
@Autowired
private RedisTemplate<Object,Object> redisTemplate;
redisTemplate.opsForValue().set(Object,Object);