提交 29869bfd 编写于 作者: 街头小贩's avatar 街头小贩

移动RedisMemberStorageCondition

上级 d1205b4f
......@@ -58,17 +58,10 @@ public class OnlineMemberRedisStorage implements OnlineMemberStorage{
}
}
}
@Override
public void refresh(HttpServletRequest request, HttpServletResponse response, MemberStatusEnum status, MemberGroupEnum group, MemberRoleEnum role){
if(!isContinue()){
return;
}
Cookie cookie = CookieUtils.queryCookie(request, metaConfig.getName()).orElse(null);
if (null == cookie) {
return;
}
String passStub = cookie.getValue();
Optional<String> afterPart = hash(passStub, Commons.getRequestIp(request)); //前缀:hashValue
Optional<String> afterPart = getRedisKey(request); //前缀:hashValue
if (afterPart.isPresent()) {
Map<String, String> data = new HashMap<>();
data.put("status", status.getSymbol()+"");
......@@ -83,38 +76,14 @@ public class OnlineMemberRedisStorage implements OnlineMemberStorage{
@Override
public void delete(HttpServletRequest request, HttpServletResponse response) {
if(!isContinue()){
return;
}
Cookie cookie = CookieUtils.queryCookie(request, metaConfig.getName()).orElse(null);
if (null == cookie) {
return;
}
String passStub = cookie.getValue();
Optional<String> afterPart = hash(passStub, Commons.getRequestIp(request)); //前缀:hashValue
Optional<String> afterPart = getRedisKey(request); //前缀:hashValue
if (afterPart.isPresent()) {
if (template.delete(metaConfig.getName() + ":" + afterPart.get())) {
expireCookie(request, response, metaConfig.getName(), metaConfig.getPath(), metaConfig.getDomain());
}
}
}
private Map<String, String> getStoreStruct(HttpServletRequest request){
if(!isContinue()){
return Collections.emptyMap();
}
Cookie cookie = CookieUtils.queryCookie(request, metaConfig.getName()).orElse(null);
if (null == cookie) {
return Collections.emptyMap();
}
String passStub = cookie.getValue();
Optional<String> afterPart = hash(passStub, Commons.getRequestIp(request)); //前缀:hashValue
if (afterPart.isPresent()) {
String redisKey = metaConfig.getName() + ":" + afterPart.get();
HashOperations<String, String, String> operation = template.opsForHash();
return operation.entries(redisKey);
}
return Collections.emptyMap();
}
@Override
public Optional<MemberSessionBean> getInstance(HttpServletRequest request, String sentinel) {
Map<String, String> data = getStoreStruct(request);
......@@ -138,6 +107,27 @@ public class OnlineMemberRedisStorage implements OnlineMemberStorage{
return null != template;
}
private Optional<String> getRedisKey(HttpServletRequest request){
if(!isContinue()){
return Optional.empty();
}
Cookie cookie = CookieUtils.queryCookie(request, metaConfig.getName()).orElse(null);
if (null == cookie) {
return Optional.empty();
}
String passStub = cookie.getValue();
return hash(passStub, Commons.getRequestIp(request)); //前缀:hashValue
}
private Map<String, String> getStoreStruct(HttpServletRequest request){
Optional<String> afterPart = getRedisKey(request); //前缀:hashValue
if (afterPart.isPresent()) {
String redisKey = metaConfig.getName() + ":" + afterPart.get();
HashOperations<String, String, String> operation = template.opsForHash();
return operation.entries(redisKey);
}
return Collections.emptyMap();
}
/**
* 序列化会员信息到Cookie中
*
......
package com.apobates.forum.thrones.controller.helper;
package com.apobates.forum.member.storage.redis;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
......
......@@ -9,7 +9,7 @@ import com.apobates.forum.member.storage.redis.OnlineMemberRedisStorage;
import com.apobates.forum.thrones.controller.helper.AuthenticationInterceptor;
import com.apobates.forum.thrones.controller.helper.MemberInviteCodeInterceptorAdapter;
import com.apobates.forum.thrones.controller.helper.OnlineDescriptorAspect;
import com.apobates.forum.thrones.controller.helper.RedisMemberStorageCondition;
import com.apobates.forum.member.storage.redis.RedisMemberStorageCondition;
import com.apobates.forum.thrones.controller.helper.RegisteChannelInterceptor;
import com.apobates.forum.thrones.controller.helper.StrategyInterceptorAdapter;
import com.apobates.forum.thrones.rss.TopicRssView;
......@@ -215,7 +215,7 @@ public class ThronesFrontConfig implements WebMvcConfigurer {
}
return redisStorageProvider;
}
@Bean
@Bean("redisStorageProvider")
@Conditional(RedisMemberStorageCondition.class)
public OnlineMemberRedisStorage getMemberRedisStorage(){
//redis
......
......@@ -27,7 +27,7 @@ site.defat.avtar=avatar
site.member.freeze=10
site.member.invite=false
site.member.register=true
# true used redis false used cookie
# true use redis, false use cookie storage MemberSessionBean
site.member.redis=false
site.meta.description=In this tutorial we show a Spring MVC RSS ATOM Content Negotiation example. Using Content Negotiation we can serve different versions of a document (or resource) at the same URI.
# \u83b7\u53d6\u5931\u8d25\u65f6\u663e\u793a\u7684\u56fe\u7247
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册