本文整理匯總了Java中com.zheng.common.util.RedisUtil類的典型用法代碼示例。如果您正苦於以下問題:Java RedisUtil類的具體用法?Java RedisUtil怎麽用?Java RedisUtil使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
RedisUtil類屬於com.zheng.common.util包,在下文中一共展示了RedisUtil類的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doUpdate
import com.zheng.common.util.RedisUtil; //導入依賴的package包/類
@Override
protected void doUpdate(Session session) {
// 如果會話過期/停止 沒必要再更新了
if(session instanceof ValidatingSession && !((ValidatingSession)session).isValid()) {
return;
}
// 更新session的最後一次訪問時間
UpmsSession upmsSession = (UpmsSession) session;
UpmsSession cacheUpmsSession = (UpmsSession) doReadSession(session.getId());
if (null != cacheUpmsSession) {
upmsSession.setStatus(cacheUpmsSession.getStatus());
upmsSession.setAttribute("FORCE_LOGOUT", cacheUpmsSession.getAttribute("FORCE_LOGOUT"));
}
RedisUtil.set(ZHENG_UPMS_SHIRO_SESSION_ID + "_" + session.getId(), SerializableUtil.serialize(session), (int) session.getTimeout() / 1000);
// 更新ZHENG_UPMS_SERVER_SESSION_ID、ZHENG_UPMS_SERVER_CODE過期時間 TODO
_log.debug("doUpdate >>>>> sessionId={}", session.getId());
}
示例2: getActiveSessions
import com.zheng.common.util.RedisUtil; //導入依賴的package包/類
/**
* 獲取會話列表
* @param offset
* @param limit
* @return
*/
public Map getActiveSessions(int offset, int limit) {
Map sessions = new HashMap();
Jedis jedis = RedisUtil.getJedis();
// 獲取在線會話總數
long total = jedis.llen(ZHENG_UPMS_SERVER_SESSION_IDS);
// 獲取當前頁會話詳情
List<String> ids = jedis.lrange(ZHENG_UPMS_SERVER_SESSION_IDS, offset, (offset + limit - 1));
List<Session> rows = new ArrayList<>();
for (String id : ids) {
String session = RedisUtil.get(ZHENG_UPMS_SHIRO_SESSION_ID + "_" + id);
// 過濾redis過期session
if (null == session) {
RedisUtil.lrem(ZHENG_UPMS_SERVER_SESSION_IDS, 1, id);
total = total - 1;
continue;
}
rows.add(SerializableUtil.deserialize(session));
}
jedis.close();
sessions.put("total", total);
sessions.put("rows", rows);
return sessions;
}
示例3: doUpdate
import com.zheng.common.util.RedisUtil; //導入依賴的package包/類
@Override
protected void doUpdate(Session session) {
// 如果會話過期/停止 沒必要再更新了
if(session instanceof ValidatingSession && !((ValidatingSession)session).isValid()) {
return;
}
// 更新session的最後一次訪問時間
UpmsSession upmsSession = (UpmsSession) session;
UpmsSession cacheUpmsSession = (UpmsSession) doReadSession(session.getId());
if (null != cacheUpmsSession) {
upmsSession.setStatus(cacheUpmsSession.getStatus());
upmsSession.setAttribute("FORCE_LOGOUT", cacheUpmsSession.getAttribute("FORCE_LOGOUT"));
}
RedisUtil.set(ZHENG_UPMS_SHIRO_SESSION_ID + "_" + session.getId(), SerializableUtil.serialize(session), (int) session.getTimeout() / 1000);
// 更新ZHENG_UPMS_SERVER_SESSION_ID、ZHENG_UPMS_SERVER_CODE過期時間 TODO
LOGGER.debug("doUpdate >>>>> sessionId={}", session.getId());
}
示例4: login
import com.zheng.common.util.RedisUtil; //導入依賴的package包/類
@ApiOperation(value = "登錄")
@RequestMapping(value = "/login", method = RequestMethod.GET)
public String login(HttpServletRequest request) {
Subject subject = SecurityUtils.getSubject();
Session session = subject.getSession();
String serverSessionId = session.getId().toString();
// 判斷是否已登錄,如果已登錄,則回跳
String code = RedisUtil.get(ZHENG_UPMS_SERVER_SESSION_ID + "_" + serverSessionId);
// code校驗值
if (StringUtils.isNotBlank(code)) {
// 回跳
String backurl = request.getParameter("backurl");
String username = (String) subject.getPrincipal();
if (StringUtils.isBlank(backurl)) {
backurl = "/";
} else {
if (backurl.contains("?")) {
backurl += "&upms_code=" + code + "&upms_username=" + username;
} else {
backurl += "?upms_code=" + code + "&upms_username=" + username;
}
}
_log.debug("認證中心帳號通過,帶code回跳:{}", backurl);
return "redirect:" + backurl;
}
return "/sso/login.jsp";
}
示例5: doCreate
import com.zheng.common.util.RedisUtil; //導入依賴的package包/類
@Override
protected Serializable doCreate(Session session) {
Serializable sessionId = generateSessionId(session);
assignSessionId(session, sessionId);
RedisUtil.set(ZHENG_UPMS_SHIRO_SESSION_ID + "_" + sessionId, SerializableUtil.serialize(session), (int) session.getTimeout() / 1000);
_log.debug("doCreate >>>>> sessionId={}", sessionId);
return sessionId;
}
示例6: forceout
import com.zheng.common.util.RedisUtil; //導入依賴的package包/類
/**
* 強製退出
* @param ids
* @return
*/
public int forceout(String ids) {
String[] sessionIds = ids.split(",");
for (String sessionId : sessionIds) {
// 會話增加強製退出屬性標識,當此會話訪問係統時,判斷有該標識,則退出登錄
String session = RedisUtil.get(ZHENG_UPMS_SHIRO_SESSION_ID + "_" + sessionId);
UpmsSession upmsSession = (UpmsSession) SerializableUtil.deserialize(session);
upmsSession.setStatus(UpmsSession.OnlineStatus.force_logout);
upmsSession.setAttribute("FORCE_LOGOUT", "FORCE_LOGOUT");
RedisUtil.set(ZHENG_UPMS_SHIRO_SESSION_ID + "_" + sessionId, SerializableUtil.serialize(upmsSession), (int) upmsSession.getTimeout() / 1000);
}
return sessionIds.length;
}
示例7: updateStatus
import com.zheng.common.util.RedisUtil; //導入依賴的package包/類
/**
* 更改在線狀態
*
* @param sessionId
* @param onlineStatus
*/
public void updateStatus(Serializable sessionId, UpmsSession.OnlineStatus onlineStatus) {
UpmsSession session = (UpmsSession) doReadSession(sessionId);
if (null == session) {
return;
}
session.setStatus(onlineStatus);
RedisUtil.set(ZHENG_UPMS_SHIRO_SESSION_ID + "_" + session.getId(), SerializableUtil.serialize(session), (int) session.getTimeout() / 1000);
}
示例8: login
import com.zheng.common.util.RedisUtil; //導入依賴的package包/類
@ApiOperation(value = "登錄")
@RequestMapping(value = "/login", method = RequestMethod.GET)
public String login(HttpServletRequest request) {
Subject subject = SecurityUtils.getSubject();
Session session = subject.getSession();
String serverSessionId = session.getId().toString();
// 判斷是否已登錄,如果已登錄,則回跳
String code = RedisUtil.get(ZHENG_UPMS_SERVER_SESSION_ID + "_" + serverSessionId);
// code校驗值
if (StringUtils.isNotBlank(code)) {
// 回跳
String backurl = request.getParameter("backurl");
String username = (String) subject.getPrincipal();
if (StringUtils.isBlank(backurl)) {
backurl = "/";
} else {
if (backurl.contains("?")) {
backurl += "&upms_code=" + code + "&upms_username=" + username;
} else {
backurl += "?upms_code=" + code + "&upms_username=" + username;
}
}
LOGGER.debug("認證中心帳號通過,帶code回跳:{}", backurl);
return "redirect:" + backurl;
}
return "/sso/login.jsp";
}
示例9: doCreate
import com.zheng.common.util.RedisUtil; //導入依賴的package包/類
@Override
protected Serializable doCreate(Session session) {
Serializable sessionId = generateSessionId(session);
assignSessionId(session, sessionId);
RedisUtil.set(ZHENG_UPMS_SHIRO_SESSION_ID + "_" + sessionId, SerializableUtil.serialize(session), (int) session.getTimeout() / 1000);
LOGGER.debug("doCreate >>>>> sessionId={}", sessionId);
return sessionId;
}
示例10: doReadSession
import com.zheng.common.util.RedisUtil; //導入依賴的package包/類
@Override
protected Session doReadSession(Serializable sessionId) {
String session = RedisUtil.get(ZHENG_UPMS_SHIRO_SESSION_ID + "_" + sessionId);
_log.debug("doReadSession >>>>> sessionId={}", sessionId);
return SerializableUtil.deserialize(session);
}
示例11: doReadSession
import com.zheng.common.util.RedisUtil; //導入依賴的package包/類
@Override
protected Session doReadSession(Serializable sessionId) {
String session = RedisUtil.get(ZHENG_UPMS_SHIRO_SESSION_ID + "_" + sessionId);
LOGGER.debug("doReadSession >>>>> sessionId={}", sessionId);
return SerializableUtil.deserialize(session);
}