调用方法 "SecurityUtils.getSubject();" 是否总是会命中 redis 数据库?
Does calling the method "SecurityUtils.getSubject();" will always hit the redis database?
我正在我的项目中实现 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
}
每个请求会话最多查找一次,较少取决于您配置的任何额外缓存。
你不会 manage/lookup sessionId 直接来自你的控制器。所有这些逻辑都是透明的,并由 Shiro and/or 您的 servlet 容器的会话管理来处理。
我正在我的项目中实现 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
}
每个请求会话最多查找一次,较少取决于您配置的任何额外缓存。
你不会 manage/lookup sessionId 直接来自你的控制器。所有这些逻辑都是透明的,并由 Shiro and/or 您的 servlet 容器的会话管理来处理。