我正在我的项目中实现redis-shiro会话管理功能,目前我对Shiro&Redis的信息很少。
我想知道是否每次调用下面的命令都会访问redis数据库,以检查redis数据库中是否存在任何sessionId。
服务代码
Subject currentUser = SecurityUtils.getSubject();
Session session = currentUser.getSession();
控制器中的代码:
public String getSomrthing(@CookieValue("JSESSIONID") String fooCookie){
callingSomeServiceMethod(fooCookie);
return "It does not matter";
}
我们是否必须像我们的服务中一样手动匹配sessionId,或者Shiro会自动匹配它,因为我的应用程序将在多实例环境中运行。
Subject currentUser = SecurityUtils.getSubject();
if(currentUser.getId.equals(fooCookie)){
//.....Some Code
//.....Some Code
}
会话将每个请求最多查找一次,更少取决于您配置的任何其他缓存。
但是,您不会直接从控制器管理/查找sessionId。所有这些逻辑都是透明的,由Shiro和/或您的servlet容器的会话管理处理。