Public long Getsessionidbyuserid (long systemid, long Customeruserid) {
if (Customeruserid = = null) {
Loggerhelper.info (This.getclass (), "Custom user ID is null.");
return default_session_id;
}
Long sessionId = GetSessionID (string.valueof (Customeruserid)); ------Determine if the user has a session record
if (sessionId = = null) { --------create a new record into the database At the same time feedback SessionID
querysession session = new Querysession (SystemID, Customeruserid);
Querysessiondao.save (session);
sessionId = Session.getid ();
}
Putsessionid (string.valueof (Customeruserid), sessionId, session_expire_minutes); Place SessionID and time-outs into Redis-----------more meaning
return sessionId;
}
Into Redis
private void Putsessionid (String userName, Long sessionId, int expireafterminutes) {
if (UserName = = NULL | | sessionId = = NULL) {
return;
}
valuedata valuedata = new Valuedata (sessionId, system.currenttimemillis () + expireafterminutes * * *) ; -------- Create a record SessionID and timeout point in time
redistemplate.boundhashops (Query_session_key). Put (UserName, valuedata);
}
Then take Redis judgment function
private Long GetSessionID (String userName) {
Valuedata value = (valuedata) Redistemplate.boundhashops (Query_session_key). get (UserName);
if (value = = null) {
if (System.currentt Imemillis () > Expiretimemillion) {--------------verify if it's over this point in time ~ ~ ~
Redistemplate.boundhashops (query_session_key). Delete (UserName);
return null;
} else {
return Value.sessionid;
}
}
Simulated Timeout Request ~ ~ ~
It's interesting to write a time-out with Redis.