1. 引入 redis 依赖

  1. <!-- 引入 redis 依赖 -->
  2. <dependency>
  3. <groupId>org.springframework.boot</groupId>
  4. <artifactId>spring-boot-starter-data-redis</artifactId>
  5. </dependency>

2. 配置redis

  1. spring:
  2. redis:
  3. database: 1
  4. host: 192.168.1.191
  5. port: 6379
  6. password: imooc

3. controller 测试

  1. @Autowired
  2. private RedisTemplate redisTemplate;
  3. redisTemplate.opsForValue().set(key, value);
  4. (String)redisTemplate.opsForValue().get(key);
  5. redisTemplate.delete(key);