Browse Source

添加redistemplate输出

lwx_dev
erdanergou 3 years ago
parent
commit
cf429a27ea
  1. 10
      src/main/java/com/dreamchaser/depository_manage/intercepter/UserInterceptor.java
  2. 5
      src/test/java/com/dreamchaser/depository_manage/OtherTest.java

10
src/main/java/com/dreamchaser/depository_manage/intercepter/UserInterceptor.java

@ -8,6 +8,7 @@ import com.dreamchaser.depository_manage.security.pool.AuthenticationTokenPool;
import com.dreamchaser.depository_manage.security.pool.RedisPool; import com.dreamchaser.depository_manage.security.pool.RedisPool;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
@ -34,11 +35,14 @@ public class UserInterceptor extends HandlerInterceptorAdapter {
} }
}; };
private static RedisPool redisPool; private static RedisPool redisPool;
private static RedisTemplate<String,String> redisTemplate;
@Autowired @Autowired
public void setRedisTemplate(RedisPool redisPool) { public void setRedisTemplate(RedisPool redisPool) {
UserInterceptor.redisPool = redisPool; UserInterceptor.redisPool = redisPool;
} }
@Autowired
public void setRedisTemplate(RedisTemplate<String,String> redisTemplate){UserInterceptor.redisTemplate = redisTemplate;}
@Override @Override
public boolean preHandle(HttpServletRequest request, public boolean preHandle(HttpServletRequest request,
@ -66,7 +70,11 @@ public class UserInterceptor extends HandlerInterceptorAdapter {
} }
System.out.println("redis请求key:"+PublicConfig.LoginRedisPrefix+userKey); System.out.println("redis请求key:"+PublicConfig.LoginRedisPrefix+userKey);
token = (String) redisPool.getRedisTemplateByDb(5).opsForHash().get(PublicConfig.LoginRedisPrefix+userKey,"usertoken"); token = (String) redisPool.getRedisTemplateByDb(5).opsForHash().get(PublicConfig.LoginRedisPrefix+userKey,"usertoken");
System.out.println("redis获取的token"+token); System.out.println("redisPool获取的token: "+token);
System.out.println("redisTemplate获取的token: "+redisTemplate.opsForHash().get(PublicConfig.LoginRedisPrefix+userKey,"usertoken"));
if(token == null){
redisPool.getRedisTemplateByDb(5).opsForHash().put("ces","wfdl","wfdl");
}
if ( "/".equals(servletPath)) { if ( "/".equals(servletPath)) {
// 如果是企业微信登录 // 如果是企业微信登录
try { try {

5
src/test/java/com/dreamchaser/depository_manage/OtherTest.java

@ -99,8 +99,9 @@ public class OtherTest {
@Test @Test
public void someTest(){ public void someTest(){
Map<String, Integer> allDepositoryNameAndId = depositoryService.findAllDepositoryNameAndId(); String local = "HXGK_GO_ZhixingCollege:ScanCode:Authentication:LoginApi_dev_e3bfa398fe9d0e1ab78a00ff59eff788";
System.out.println(JSONObject.toJSONString(allDepositoryNameAndId)); Object usertoken = redisPool.getRedisTemplateByDb(5).opsForHash().get(local, "usertoken");
System.out.println(usertoken);
} }
@Test @Test

Loading…
Cancel
Save