Commit 5dc0935d by 陶湘宇 Committed by 284718418@qq.com

修复redis缓存不能持久生效

parent 051cd5fc
...@@ -51,10 +51,23 @@ public class RedisSessionInterceptor implements HandlerInterceptor { ...@@ -51,10 +51,23 @@ public class RedisSessionInterceptor implements HandlerInterceptor {
*/ */
// 无论访问的地址是不是正确的,都进行登录验证,登录成功后的访问再进行分发,404的访问自然会进入到错误控制器中 // 无论访问的地址是不是正确的,都进行登录验证,登录成功后的访问再进行分发,404的访问自然会进入到错误控制器中
HttpSession session = request.getSession(); HttpSession session = request.getSession();
System.out.println("SID===="+session.getId()); //String Sid
System.out.println("RSID==------=="+session.getId());
Object ai = redisUtil.getAttribute(session.getId(),"ai"); System.out.println("ROSID=-----==="+request.getRequestedSessionId());
Object ui = redisUtil.getAttribute(session.getId(),"ui"); /**
* 新ID替换旧ID完成登陆
*/
if(session.getId()!=request.getRequestedSessionId()&&redisUtil.hasKey(request.getRequestedSessionId())&& redisUtil.getAttribute(session.getId(),"ai")==null){
try {
redisUtil.reNmae(request.getRequestedSessionId(), session.getId());
}catch (Exception e){
e.printStackTrace();
}
}
Object nai = redisUtil.getAttribute(session.getId(),"ai");
Object nui = redisUtil.getAttribute(session.getId(),"ui");
Object ai = nai!=null?nai:redisUtil.getAttribute(request.getRequestedSessionId(),"ai");
Object ui = nui!=null?nui:redisUtil.getAttribute(request.getRequestedSessionId(),"ui");
if(ui==null&&ai==null) { if(ui==null&&ai==null) {
response401(response); response401(response);
return false; return false;
......
...@@ -608,9 +608,13 @@ public class RedisUtil { ...@@ -608,9 +608,13 @@ public class RedisUtil {
public Object rifhtPop(String listKey){ public Object rifhtPop(String listKey){
//绑定操作 //绑定操作
BoundListOperations<String, Object> boundValueOperations = redisTemplate.boundListOps(listKey); BoundListOperations<String, Object> boundValueOperations = redisTemplate.boundListOps(listKey);
return boundValueOperations.rightPop(); return boundValueOperations.rightPop();
} }
public void reNmae(String oldKey,String newKey){
redisTemplate.rename(oldKey,newKey);
}
//=========BoundListOperations 用法 End============ //=========BoundListOperations 用法 End============
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment