Python知识分享网 - 专业的Python学习网站 学Python,上Python222
JWT 实现登录认证 + Token 自动续期方案,这才是正确的使用姿势! PDF 下载
匿名网友发布于:2024-01-14 10:09:05
(侵权举报)
(假如点击没反应,多刷新两次就OK!)

JWT 实现登录认证 + Token 自动续期方案,这才是正确的使用姿势! PDF 下载  图1

 

 

 

 

资料简介:

 

Redis工具类
public final class RedisServiceImpl implements RedisService {
/**
* 过期时长
*/
private final Long DURATION = 1 * 24 * 60 * 60 * 1000L;
@Resource
private RedisTemplate redisTemplate;
private ValueOperations<String, String> valueOperations;
@PostConstruct
public void init() {
RedisSerializer redisSerializer = new StringRedisSerializer();
redisTemplate.setKeySerializer(redisSerializer);
redisTemplate.setValueSerializer(redisSerializer);
redisTemplate.setHashKeySerializer(redisSerializer);
redisTemplate.setHashValueSerializer(redisSerializer);
valueOperations = redisTemplate.opsForValue();
}
@Override
public void set(String key, String value) {
valueOperations.set(key, value, DURATION, TimeUnit.MILLISECONDS);
log.info("key={}, value is: {} into redis cache", key, value);
}
@Override
public String get(String key) {
String redisValue = valueOperations.get(key);
log.info("get from redis, value is: {}", redisValue);
return redisValue;
}
@Override
Java大后端
专注分享Java技术干货,包括Java多线程、IO、JVM、Spring Boot、Spring Cloud、…
公众号
 public boolean delete(String key) {
boolean result = redisTemplate.delete(key);
log.info("delete from redis, key is: {}", key);
return result;
}
@Override
public Long getExpireTime(String key) {
return valueOperations.getOperations().getExpire(key);
}
}