From e1a62ec62e7331d97af9302e90e1ce44af8235eb Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期三, 27 一月 2021 15:26:55 +0800 Subject: [PATCH] 拼多多授权绑定 --- fanli/src/main/java/com/yeshi/fanli/aspect/RequestSerializableServiceAspect.java | 30 ++++++++++-------------------- 1 files changed, 10 insertions(+), 20 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/aspect/RequestSerializableServiceAspect.java b/fanli/src/main/java/com/yeshi/fanli/aspect/RequestSerializableServiceAspect.java index caef6ed..24b01c2 100644 --- a/fanli/src/main/java/com/yeshi/fanli/aspect/RequestSerializableServiceAspect.java +++ b/fanli/src/main/java/com/yeshi/fanli/aspect/RequestSerializableServiceAspect.java @@ -4,6 +4,7 @@ import javax.annotation.Resource; +import com.yeshi.fanli.util.RedisManager; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.Signature; import org.aspectj.lang.annotation.Around; @@ -17,20 +18,20 @@ import org.springframework.expression.spel.support.StandardEvaluationContext; import org.springframework.stereotype.Component; -import com.yeshi.fanli.log.LogHelper; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.annotation.RequestSerializableByKeyService; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; +import redis.clients.jedis.params.SetParams; @Component @Aspect public class RequestSerializableServiceAspect { @Resource - private JedisPool jedisPool; + private RedisManager redisManager; private ExpressionParser parser = new SpelExpressionParser(); @@ -67,15 +68,15 @@ + cacheKey; cacheKey = "service-" + StringUtil.Md5(cacheKey); // jiedis鍘熷瓙鎬у仛鎷︽埅 - Jedis jedis = jedisPool.getResource(); + Jedis jedis = redisManager.getJedis(); try { Constant.waitingThreadSet.add(Thread.currentThread().getId()); - long result = 0; + String result = null; long startTime = System.currentTimeMillis(); // 绛夊緟鍝嶅簲 - while (result <= 0) { - result = jedis.setnx(cacheKey, "1"); - if (result <= 0) { + while (StringUtil.isNullOrEmpty(result)) { + result = jedis.set(cacheKey, "1", new SetParams().nx().ex(30)); + if (StringUtil.isNullOrEmpty(result)) { try { Thread.sleep(50); } catch (InterruptedException e) { @@ -85,34 +86,23 @@ Constant.waitingThreadSet.remove(Thread.currentThread().getId()); return null; } - } else { - // 璁剧疆30绉掑鐞嗘椂闂� - jedis.expire(cacheKey, 30); } } - if (result > 0) { + if (!StringUtil.isNullOrEmpty(result)) { try { return joinPoint.proceed(); - } catch (Throwable e) { - e.printStackTrace(); - LogHelper.errorDetailInfo(e); } finally { jedis.del(cacheKey); Constant.waitingThreadSet.remove(Thread.currentThread().getId()); } } } finally { - jedisPool.returnResource(jedis); + jedis.close(); } } } catch (Exception e) {// 鍘熷瓙鎬т繚鎶ゅ嚭閿� - try { return joinPoint.proceed(); - } catch (Throwable e1) { - e.printStackTrace(); - LogHelper.errorDetailInfo(e1); - } } } } catch (NoSuchMethodException e) { -- Gitblit v1.8.0