一、SpringBoot 集成Redis步骤:
1.导入spring-boot-starter-dada-redis起步依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
2.在yml配置文件中配置redis连接信息
spring:
data:
redis:
host: 192.168.71.132
port: 6379
password: 123456
database: 1
3.调用API(StringRedisTemplate)完成字符串的存取操作
@SpringBootTest//如果在测试类上添加了这个注解,那么将来单元测试方法执行之前,会先初始化Spring容器
public class RedisTest {
@Autowired
private StringRedisTemplate stringRedisTemplate;
@Test
public void testSet(){
//往reids中存储一个键值对 StringRedisTemplate
ValueOperations<String, String> operations = stringRedisTemplate.opsForValue();
operations.set("username","zhangsan");
}
}
二、令牌主动失效机制