日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

利用redis实现分布式请求防重复提交

發(fā)布時(shí)間:2025/4/16 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 利用redis实现分布式请求防重复提交 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>

1.自定義注解類Token

@Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface Token {String flag() default ""; }

2.在需要攔截的路徑上加自定義注解

@Token @RequestMapping(value = "/pda/pick-task/list") public RespJson getPickTask(@RequestParam("whNo") String whNo,@RequestParam(value = "sourceType", required = false) Integer sourceType,@RequestParam(value = "retrieveValue", required = false) String retrieveValue,@RequestParam(value = "realTimePick", required = false, defaultValue = "0") int realTimePick,@RequestParam(value = "taskGroupNo", required = false) String taskGroupNo) { ...

3.利用切面攔截請(qǐng)求

@Aspect @Component public class MethodInterceptor {private Logger logger = LoggerFactory.getLogger(MethodInterceptor.class); /*** 重復(fù)請(qǐng)求攔截** @param joinPoint* @return* @throws Throwable*/ @Around("@annotation(com.haiziwang.kwms.common.annotation.Token)") public Object repeatRequestAround(ProceedingJoinPoint joinPoint) throws Throwable {MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();Method currentMethod = joinPoint.getTarget().getClass().getMethod(methodSignature.getName(), methodSignature.getParameterTypes());IKMEMCache cache = KMemServiceImpl.getCache();//拼接簽名StringBuilder signBuffer = new StringBuilder(currentMethod.getAnnotation(RequestMapping.class).value()[0]);Object[] args = joinPoint.getArgs();for (Object object : args) {if (object != null) {String str = "";try {str = JSONObject.toJSONString(object);} catch (Exception e) {}signBuffer.append("^").append(str);}}String tokenKey = signBuffer.toString();if (StringUtils.isNotBlank(cache.readFromHash(RedisKeyType.TOKEN.getName(), tokenKey))) {if (StringConstants.WCS.equals(currentMethod.getAnnotation(Token.class).flag())) {throw new WMS3CheckedException(WMS3ExceptionCode.WCS_REPEAT_REQUEST_EXCEPTION);}if (currentMethod.getReturnType() == RespJson.class) {throw new WMS3CheckedException(WMS3ExceptionCode.REPEAT_REQUEST_EXCEPTION);}if (currentMethod.getReturnType() == PageRespJson.class) {throw new WMS3CheckedException(WMS3ExceptionCode.REPEAT_REQUEST_PAGE_EXCEPTION);}}cache.write4Hash(RedisKeyType.TOKEN.getName(), tokenKey, "token");try {return joinPoint.proceed();} finally {cache.deleteHashFields(RedisKeyType.TOKEN.getName(), tokenKey);} }

?

轉(zhuǎn)載于:https://my.oschina.net/u/2485283/blog/1859323

總結(jié)

以上是生活随笔為你收集整理的利用redis实现分布式请求防重复提交的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。