| | |
| | | package com.yeshi.fanli.manager.util;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import com.yeshi.fanli.util.RedisManager;
|
| | | import org.springframework.stereotype.Component;
|
| | |
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | |
|
| | | import redis.clients.jedis.Jedis;
|
| | | import redis.clients.jedis.JedisPool;
|
| | | import redis.clients.jedis.params.SetParams;
|
| | |
|
| | | @Component
|
| | | public class AtomMethodCallManager {
|
| | |
|
| | | @Resource
|
| | | private RedisManager redisManager;
|
| | |
|
| | | /**
|
| | | * 事件执行
|
| | | * |
| | | * @param key
|
| | | * 事件唯一标识,要与具体的业务逻辑相结合
|
| | | * @param call
|
| | | */
|
| | | public void excute(String key, AtomMethodCallInterface call) {
|
| | | String redisKey = "atom-" + StringUtil.Md5(key);
|
| | | Jedis jedis = redisManager.getJedis();
|
| | | try {
|
| | | if (StringUtil.isNullOrEmpty(jedis.set(redisKey, "1", new SetParams().nx().ex(60)))) {
|
| | | System.out.println("请稍后再试");
|
| | | return;
|
| | | }
|
| | | call.excute();
|
| | | } finally {
|
| | | jedis.del(redisKey);
|
| | | jedis.close();
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | | package com.yeshi.fanli.manager.util; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.yeshi.fanli.util.RedisManager; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | |
| | | import redis.clients.jedis.Jedis; |
| | | import redis.clients.jedis.JedisPool; |
| | | import redis.clients.jedis.params.SetParams; |
| | | |
| | | @Component |
| | | public class AtomMethodCallManager { |
| | | |
| | | @Resource |
| | | private RedisManager redisManager; |
| | | |
| | | /** |
| | | * 事件执行 |
| | | * |
| | | * @param key |
| | | * 事件唯一标识,要与具体的业务逻辑相结合 |
| | | * @param call |
| | | */ |
| | | public void excute(String key, AtomMethodCallInterface call) { |
| | | String redisKey = "atom-" + StringUtil.Md5(key); |
| | | Jedis jedis = redisManager.getJedis(); |
| | | try { |
| | | if (StringUtil.isNullOrEmpty(jedis.set(redisKey, "1", new SetParams().nx().ex(60)))) { |
| | | System.out.println("请稍后再试"); |
| | | return; |
| | | } |
| | | call.excute(); |
| | | } finally { |
| | | jedis.del(redisKey); |
| | | jedis.close(); |
| | | } |
| | | } |
| | | |
| | | } |