注解 获取 存入redis
来源:互联网 发布:淘宝英文版网址 编辑:程序博客网 时间:2024/06/08 15:35
<!-- 创建注解 -->
@Target({ ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface CreditSourceCache {
/**
* 缓存key
* @return
*/
String keyName() default "";
/**
* 缓存值
* @return
*/
String keyValue() default "";
/**
* 是否收费 FEE-收费,NOTFEE-免费
* @return
*/
String fee() default "FEE";
/**
* 缓存时间
* @return
*/
int cacheTime() default 60*60*24;
}
<!-- 加注解 -->
@CreditSourceType(mainName = CreditSourceName.BaiDu, childName = "risk")
@CreditSourceCache(keyName = "baiDuRisk_id#{#entity.getIdCard()}_phone_#{#entity.getPhoneNumber()}", cacheTime = 86401)
public OriginalResult<String> queryPanShiRiskList(BaiDuPanShiEntity baiDuPanShiEntity){}
@Aspect
@Componentpublic class BusinessInterceptor {
public static final String BUSINESS_CREDIT_SOURCE = "execution(* com.mobanker.feature.credit.business.creditSource.api.*.*(..))";
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private CreditSendBigDataBusiness creditSendBigDataBusiness;
@Autowired
private RedisBusiness redisBusiness;
@Around(value = BUSINESS_CREDIT_SOURCE)
public Object sendLogData(ProceedingJoinPoint jp){
logger.debug("pointcut start...");
long startTime = System.currentTimeMillis();
CreditSourceBigData bigData = new CreditSourceBigData();
//缓存信息
int cacheTime = 60*60*24;
String keyName = null;
String fee = "FEE";
//获取当前类
Class<?> classTarget = jp.getTarget().getClass();
//获取目标方法体参数
Object[] params = jp.getArgs();
//获取方法名
String methodName = jp.getSignature().getName();
//获取方法签名类型
Class<?>[] par = ((MethodSignature) jp.getSignature()).getParameterTypes();
//方法前面第一个参数
Object firstParamObj = params[0];
//方法返回值
Object returnValue = null;
Method objMethod = null;
try {
objMethod = classTarget.getMethod(methodName, par);
} catch (NoSuchMethodException e) {
logger.error("", e);
return null;
}
//获取缓存注解信息
CreditSourceCache creditSourceCache = objMethod.getAnnotation(CreditSourceCache.class);
if (creditSourceCache != null){
String spelExpress = creditSourceCache.keyName();
fee = creditSourceCache.fee();
cacheTime = creditSourceCache.cacheTime();
if (StringUtils.isNotBlank(spelExpress)){
keyName = getCacheKeyBySpEL(firstParamObj, spelExpress);
logger.debug("spelExpress:{}, fee:{}, cacheTime:{}, cacheKeyName:{}", spelExpress, fee, cacheTime, keyName);
//从缓存获取值
String cacheValue = redisBusiness.getValue(keyName);
if (StringUtils.isNotBlank(cacheValue)){
OriginalResult<String> oResult = JSONObject.parseObject(cacheValue, new TypeReference<OriginalResult<String>>(){});
logger.debug("from cache, value = {}", cacheValue);
return oResult;
}
}
}
try {
returnValue = jp.proceed();
} catch (Throwable throwable) {
logger.error("切面调用方法error", throwable);
return null;
}
if (creditSourceCache != null){
long endTime = System.currentTimeMillis();
if (params != null && params.length > 0){
String paramClassName = firstParamObj.getClass().getName();
//组装BigData数据
bigData = assembleCreditSourceBigData(bigData, paramClassName, firstParamObj, objMethod);
}
bigData.setClacTime(endTime - startTime);
bigData.setInStr(JSONObject.toJSONString(firstParamObj));
bigData.setOutStr(returnValue == null ? "null" : JSONObject.toJSONString(returnValue));
bigData.setCreateTime(new Date());
//TODO 发送到大数据
creditSendBigDataBusiness.sendBigData(bigData);
//TODO 解析各征信源返回报文,做缓存信息,剔除错误信息,只缓存正确的信息
if (returnValue != null){
OriginalResult<String> originalResult = (OriginalResult<String>)returnValue;
boolean checkFlag = false;
try {
checkFlag = checkResultCanCache(originalResult, bigData.getCreditMainName(), bigData.getCreditChildName());
}catch (Exception e) {
logger.error("", e);
}
if(checkFlag){
logger.debug("缓存到redis, keyName={}, value={}, cacheTime={}", keyName, originalResult, cacheTime);
redisBusiness.setValue(keyName, JSONObject.toJSONString(originalResult), cacheTime);
}
}
}
logger.debug("切点结束。。。");
return returnValue;
}
- 注解 获取 存入redis
- session数据存入redis
- session存入redis
- session 存入 redis
- 把session 存入 redis
- 将redis slowlog存入MySQL
- 让php Session 存入 redis 配置方法
- 将数据存入redis进行读取数据
- 如何将session存入redis或memcache
- Spring Cache注解+Redis
- Spring Cache注解+Redis
- redis.conf配置文件注解
- redis注解开发详解
- Redis缓存注解
- Springboot 使用Redis注解
- Spring boot redis注解
- struts2的值栈存入和获取
- 微信小程序 获取openid 存入数据库 C#
- 动态代理在反射中的运用
- 如何用命令测试Linux 硬盘的读写速度
- SOCKET通信基础
- android踩坑记录-持续更新
- CentOS 7 PHP7 启用session扩展
- 注解 获取 存入redis
- 冒泡排序和快速排序(java实现)
- 《Flask Web开发》读书笔记(0)目录(关键词:)
- 线程基础
- 菱形继承与虚继承
- mysql在centos客户端
- ButterKnife的集成和使用
- 【java基础总结】1.关键字
- lxc与host的coredump配置