Redis 存在 userInfo技巧
/**
* 设置redis缓存方法
* @param user 用户模型
* @return 返回uuid
*/
private String setRedis(User user){
Map<String,Object> map=new HashMap<>();
map.put("userId",user.getId());
map.put("userName",user.getUserName());
map.put("password",user.getUserPwd());
map.put("phone",user.getPhone());
//是否过期 大于-1 是true 未过期
Date today=new Date();
Date expire=user.getExpireDate();
map.put("expireDate",expire);//过期时间
map.put("expire",expire.compareTo(today));//处理-是否已经过期
//org组织码(授权则是1)
map.put("org",user.getOrg());
map.put("valid",user.getIsValid());
//uuid 唯一值(key)
String uuid= UUID.randomUUID()+"";
//存入redis 30分钟
redisUtil.hashSetAll(uuid,map);
redisUtil.expire(uuid,30L,TimeUnit.MINUTES);
return uuid;
}
/**
* 2.退出当前账号
* @param request 请求
*/
public void userLogout(HttpServletRequest request){
String key=CookieUtil.getKeyFromTokenCookie(request);
//删除redis
ThrowException.illegal(!redisUtil.remove(key),"退出失败!");
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/107108.html