springboot集成redis

1.导入spring-boot-starter-data-redis起步依赖

2.在配置文件中, 配置redis连接信息

3.调用API(StringRedisTemplate)完成字符串的存取操作

//把token存储在redis中
    ValueOperations<String, String> operations = stringRedisTemplate.opsForValue();
    operations.set(token,token,1, TimeUnit.HOURS);
//删除存储在redis中的token
 ValueOperations<String, String> operations = stringRedisTemplate.opsForValue();
    operations.getOperations().delete(token);
posted @ 2024-03-18 20:16  kiss_sheep  阅读(35)  评论(0)    收藏  举报