admin
2020-07-04 e04f81915e100107eca5fe16ba44898f3a0dbd55
redis指定数据库
15个文件已修改
1168 ■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/aspect/ActiveUserAspect.java 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/aspect/RequestSerializableAspect.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/aspect/RequestSerializableServiceAspect.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/aspect/integral/IntegralGetFrequencyLimitAspect.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/TestController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/manager/util/AtomMethodCallManager.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/msg/MsgOrderDetailServiceImpl.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserAccountServiceImpl.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/RedisManager.java 1097 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/resource/env-dev/redis.properties 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/resource/env-pro-by/redis.properties 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/resource/env-pro-job/redis.properties 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/resource/env-pro/redis.properties 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/resource/env-sandbox/redis.properties 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/resource/spring.xml 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/aspect/ActiveUserAspect.java
@@ -5,6 +5,7 @@
import javax.annotation.Resource;
import com.yeshi.fanli.util.RedisManager;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Aspect;
@@ -47,17 +48,7 @@
@Aspect
public class ActiveUserAspect {
    @Resource
    private JedisPool jedisPool;
    @Resource
    private UserInfoModifyRecordService userInfoModifyRecordService;
    @Resource
    private UserInfoExtraService userInfoExtraService;
    @Resource
    private IntegralGetService integralGetService;
    private RedisManager redisManager;
    private ExpressionParser parser = new SpelExpressionParser();
@@ -93,7 +84,7 @@
                        @Override
                        public void run() {
                            String key = "useractive-" + uidStr;
                            Jedis jedis = jedisPool.getResource();
                            Jedis jedis =redisManager.getJedis();
                            try {
                                if (!StringUtil.isNullOrEmpty(jedis.set(key, "1", new SetParams().nx().ex(Constant.IS_TEST?10:300)))) {
                                    try {
fanli/src/main/java/com/yeshi/fanli/aspect/RequestSerializableAspect.java
@@ -7,6 +7,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;
@@ -36,7 +37,7 @@
@Order(4)
public class RequestSerializableAspect {
    @Resource
    private JedisPool jedisPool;
    private RedisManager redisManager;
    private ExpressionParser parser = new SpelExpressionParser();
@@ -95,7 +96,7 @@
                        String cacheAlias = cacheKey;
                        cacheKey = "rs-" + StringUtil.Md5(cacheKey);
                        // jiedis原子性做拦截
                        Jedis jedis = jedisPool.getResource();
                        Jedis jedis = redisManager.getJedis();
                        long threadId = Thread.currentThread().getId();
                        try {
                            Constant.waitingThreadSet.add(threadId);
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;
@@ -30,7 +31,7 @@
public class RequestSerializableServiceAspect {
    @Resource
    private JedisPool jedisPool;
    private RedisManager redisManager;
    private ExpressionParser parser = new SpelExpressionParser();
@@ -67,7 +68,7 @@
                                + cacheKey;
                        cacheKey = "service-" + StringUtil.Md5(cacheKey);
                        // jiedis原子性做拦截
                        Jedis jedis = jedisPool.getResource();
                        Jedis jedis = redisManager.getJedis();
                        try {
                            Constant.waitingThreadSet.add(Thread.currentThread().getId());
                            String result = null;
fanli/src/main/java/com/yeshi/fanli/aspect/integral/IntegralGetFrequencyLimitAspect.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;
@@ -28,7 +29,7 @@
public class IntegralGetFrequencyLimitAspect {
    @Resource
    private JedisPool jedisPool;
    private RedisManager redisManager;
    private ExpressionParser parser = new SpelExpressionParser();
@@ -61,7 +62,7 @@
                String catchKey = "integral-get-frequency-" + StringUtil.Md5(generateKeyBySpEL(key, joinPoint));
                Jedis jedis = jedisPool.getResource();
                Jedis jedis =redisManager.getJedis();
                try {
                    if (jedis.setnx(catchKey, "1") > 0) {
                        jedis.expire(catchKey, timeS);
fanli/src/main/java/com/yeshi/fanli/controller/TestController.java
@@ -330,7 +330,7 @@
    @RequestMapping(value = "getBinFaRedisKey")
    public void getPinFaRedisKey(PrintWriter out) {
        JSONArray array = new JSONArray();
        Jedis jedis = jedisPool.getResource();
        Jedis jedis = redisManager.getJedis();
        try {
            Set<String> sets = jedis.keys("rs-*");
            for (Iterator<String> its = sets.iterator(); its.hasNext();)
fanli/src/main/java/com/yeshi/fanli/manager/util/AtomMethodCallManager.java
@@ -2,6 +2,7 @@
import javax.annotation.Resource;
import com.yeshi.fanli.util.RedisManager;
import org.springframework.stereotype.Component;
import com.yeshi.fanli.util.StringUtil;
@@ -14,7 +15,7 @@
public class AtomMethodCallManager {
    @Resource
    private JedisPool jedisPool;
    private RedisManager redisManager;
    /**
     * 事件执行
@@ -25,7 +26,7 @@
     */
    public void excute(String key, AtomMethodCallInterface call) {
        String redisKey = "atom-" + StringUtil.Md5(key);
        Jedis jedis = jedisPool.getResource();
        Jedis jedis = redisManager.getJedis();
        try {
            if (StringUtil.isNullOrEmpty(jedis.set(redisKey, "1", new SetParams().nx().ex(60)))) {
                System.out.println("请稍后再试");
fanli/src/main/java/com/yeshi/fanli/service/impl/order/msg/MsgOrderDetailServiceImpl.java
@@ -5,6 +5,7 @@
import javax.annotation.Resource;
import com.yeshi.fanli.util.RedisManager;
import org.springframework.stereotype.Service;
import com.yeshi.fanli.dao.mybatis.msg.MsgOrderDetailMapper;
@@ -32,7 +33,7 @@
    private UserMsgReadStateService userMsgReadStateService;
    @Resource
    private JedisPool jedisPool;
    private RedisManager redisManager;
    
    @Resource
    private MsgExtraService msgExtraService;
@@ -55,7 +56,7 @@
        
        
        // 锁住订单号
        Jedis jedis = jedisPool.getResource();
        Jedis jedis = redisManager.getJedis();
        try {
            String key = "rs-order-" + detail.getOrderId();
            if (jedis.setnx(key, "1") > 0) {
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserAccountServiceImpl.java
@@ -846,7 +846,7 @@
        // 采用redis事务防止一个手机号多次注册问题
        String watchKey = StringUtil.Md5("REGISTER:" + phone);
        Jedis jedis = jedisPool.getResource();
        Jedis jedis = redisManager.getJedis();
        try {
            jedis.watch(watchKey);
            if (jedis.get(watchKey) != null && Integer.parseInt(jedis.get(watchKey)) > 1)
@@ -944,7 +944,7 @@
        // 采用redis事务防止一个手机号多次注册问题
        String watchKey = StringUtil.Md5("REGISTER:" + phone);
        Jedis jedis = jedisPool.getResource();
        Jedis jedis = redisManager.getJedis();
        try {
            jedis.watch(watchKey);
            if (jedis.get(watchKey) != null && Integer.parseInt(jedis.get(watchKey)) > 1)
@@ -1007,7 +1007,7 @@
        // 采用redis事务防止一个微信号多次注册问题
        String watchKey = StringUtil.Md5("REGISTER:" + weiXinUser.getUnionid());
        Jedis jedis = jedisPool.getResource();
        Jedis jedis = redisManager.getJedis();
        try {
            jedis.watch(watchKey);
            if (jedis.get(watchKey) != null && Integer.parseInt(jedis.get(watchKey)) > 1)
@@ -1424,7 +1424,7 @@
        // 采用redis事务防止一个微信号多次注册问题
        String watchKey = StringUtil.Md5("REGISTER:" + weiXinUser.getUnionid());
        Jedis jedis = jedisPool.getResource();
        Jedis jedis = redisManager.getJedis();
        try {
            jedis.watch(watchKey);
            if (jedis.get(watchKey) != null && Integer.parseInt(jedis.get(watchKey)) > 1)
fanli/src/main/java/com/yeshi/fanli/util/RedisManager.java
@@ -38,617 +38,620 @@
@Component
public class RedisManager {
    @Resource
    private JedisPool jedisPool;
    @Resource
    private JedisPool jedisPool;
    @Resource
    private TaoBaoShopService taoBaoShopService;
    @Resource
    private TaoBaoShopService taoBaoShopService;
    @Resource
    private TaoBaoUnionConfigService taoBaoUnionConfigService;
    @Resource
    private TaoBaoUnionConfigService taoBaoUnionConfigService;
    @Resource
    private ConfigService configService;
    @Resource
    private ConfigService configService;
    /**
     * 缓存字符串
     *
     * @param key
     * @param value
     */
    private void setString(String key, String value) {
        Jedis jedis = jedisPool.getResource();
        SetParams params=new SetParams().nx().ex(60);
        jedis.set(key, value, params);
        try {
            jedis.set(key, value);
        } finally {
            jedis.close();
        }
    public Jedis getJedis() {
        Jedis jedis = jedisPool.getResource();
        return jedis;
    }
    }
    /**
     * 缓存字符串
     *
     * @param key
     * @param value
     */
    private void setString(String key, String value) {
        Jedis jedis = getJedis();
        SetParams params = new SetParams().nx().ex(60);
        jedis.set(key, value, params);
        try {
            jedis.set(key, value);
        } finally {
            jedis.close();
        }
    /**
     * 删除某个键值
     *
     * @param key
     * @param value
     */
    private void removeKey(String key) {
        Jedis jedis = jedisPool.getResource();
        try {
            jedis.del(key);
        } finally {
            jedis.close();
        }
    }
    }
    /**
     * 删除某个键值
     *
     * @param key
     * @param value
     */
    private void removeKey(String key) {
        Jedis jedis = getJedis();
        try {
            jedis.del(key);
        } finally {
            jedis.close();
        }
    /**
     * 缓存字符串
     *
     * @param key
     * @param value
     * @param seconds
     *            -缓存时间(s)
     */
    private void setString(String key, String value, int seconds) {
        Jedis jedis = jedisPool.getResource();
        try {
            jedis.setex(key, seconds, value);
        } finally {
            jedis.close();
        }
    }
    }
    private String getString(String key) {
        Jedis jedis = jedisPool.getResource();
        try {
            return jedis.get(key);
        } finally {
            jedis.close();
        }
    }
    /**
     * 缓存字符串
     *
     * @param key
     * @param value
     * @param seconds -缓存时间(s)
     */
    private void setString(String key, String value, int seconds) {
        Jedis jedis = getJedis();
        try {
            jedis.setex(key, seconds, value);
        } finally {
            jedis.close();
        }
    }
    public void increase(String key) {
        Jedis jedis = jedisPool.getResource();
        try {
            jedis.incr(key);
        } finally {
            jedis.close();
        }
    }
    private String getString(String key) {
        Jedis jedis = getJedis();
        try {
            return jedis.get(key);
        } finally {
            jedis.close();
        }
    }
    public void expire(String key, int seconds) {
        Jedis jedis = jedisPool.getResource();
        try {
            jedis.expire(key, seconds);
        } finally {
            jedis.close();
        }
    }
    public void increase(String key) {
        Jedis jedis = getJedis();
        try {
            jedis.incr(key);
        } finally {
            jedis.close();
        }
    }
    public void cacheCommonString(String key, String value, int seconds) {
        setString(key, value, seconds);
    }
    public void expire(String key, int seconds) {
        Jedis jedis = getJedis();
        try {
            jedis.expire(key, seconds);
        } finally {
            jedis.close();
        }
    }
    public void cacheCommonString(String key, String value) {
        setString(key, value);
    }
    public void cacheCommonString(String key, String value, int seconds) {
        setString(key, value, seconds);
    }
    public String getCommonString(String key) {
        return getString(key);
    }
    public void cacheCommonString(String key, String value) {
        setString(key, value);
    }
    public void removeCommonString(String key) {
        removeKey(key);
    }
    public String getCommonString(String key) {
        return getString(key);
    }
    /**
     * 临时存储淘宝的商品详情
     *
     * @param goods
     */
    public void saveTaoBaoGoodsBriefTemp(TaoBaoGoodsBrief goods) {
        if (goods == null)
            return;
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoGoodsTemp, goods.getAuctionId() + "");
        if (Constant.IS_OUTNET) {
            // 暂存4个小时的分享
            cacheCommonString(key, JsonUtil.getSimpleGson().toJson(goods), 60 * 60 * 4);
        }
    }
    public void removeCommonString(String key) {
        removeKey(key);
    }
    public TaoBaoGoodsBrief getTaoBaoGoodsTemp(Long auctionId) {
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoGoodsTemp, auctionId + "");
        String value = getCommonString(key);
        if (!StringUtil.isNullOrEmpty(value)) {
            return JsonUtil.getSimpleGson().fromJson(value, TaoBaoGoodsBrief.class);
        }
        return null;
    }
    /**
     * 临时存储淘宝的商品详情
     *
     * @param goods
     */
    public void saveTaoBaoGoodsBriefTemp(TaoBaoGoodsBrief goods) {
        if (goods == null)
            return;
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoGoodsTemp, goods.getAuctionId() + "");
        if (Constant.IS_OUTNET) {
            // 暂存4个小时的分享
            cacheCommonString(key, JsonUtil.getSimpleGson().toJson(goods), 60 * 60 * 4);
        }
    }
    /**
     * 删除缓存
     *
     * @param auctionId
     */
    public void deleteTaoBaoGoodsBrief(Long auctionId) {
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoGoods, auctionId + "");
        if (Constant.IS_OUTNET)
            removeKey(key);
    }
    public TaoBaoGoodsBrief getTaoBaoGoodsTemp(Long auctionId) {
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoGoodsTemp, auctionId + "");
        String value = getCommonString(key);
        if (!StringUtil.isNullOrEmpty(value)) {
            return JsonUtil.getSimpleGson().fromJson(value, TaoBaoGoodsBrief.class);
        }
        return null;
    }
    public TaoBaoGoodsBrief getTaoBaoGoodsBrief(long auctionId) throws TaobaoGoodsDownException {
        long startTime = System.currentTimeMillis();
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoGoods, auctionId + "");
        String value = "";
        if (Constant.IS_OUTNET)
            value = getCommonString(key);
    /**
     * 删除缓存
     *
     * @param auctionId
     */
    public void deleteTaoBaoGoodsBrief(Long auctionId) {
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoGoods, auctionId + "");
        if (Constant.IS_OUTNET)
            removeKey(key);
    }
        if (StringUtil.isNullOrEmpty(value)) {
            TaoBaoGoodsBrief goods = null;
    public TaoBaoGoodsBrief getTaoBaoGoodsBrief(long auctionId) throws TaobaoGoodsDownException {
        long startTime = System.currentTimeMillis();
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoGoods, auctionId + "");
        String value = "";
        if (Constant.IS_OUTNET)
            value = getCommonString(key);
            goods = TaoKeApiUtil.searchGoodsDetail(auctionId);
        if (StringUtil.isNullOrEmpty(value)) {
            TaoBaoGoodsBrief goods = null;
            if (goods != null)
                // 缓存20分钟
                if (Constant.IS_OUTNET)
                cacheCommonString(key, JsonUtil.getSimpleGson().toJson(goods), 60 * 20);
            LogHelper.test(auctionId + "-获取商品详情耗时:" + (System.currentTimeMillis() - startTime));
            return goods;
        } else {// 直接取缓存
            return JsonUtil.getSimpleGson().fromJson(value, TaoBaoGoodsBrief.class);
        }
    }
            goods = TaoKeApiUtil.searchGoodsDetail(auctionId);
    public List<ImageInfo> getTaoBaoGoodsDetailImgs(long auctionId, SystemEnum system) {
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoGoodsDetailimgs, auctionId + "");
        String value = "";
        if (Constant.IS_OUTNET)
            value = getCommonString(key);
            if (goods != null)
                // 缓存20分钟
                if (Constant.IS_OUTNET)
                    cacheCommonString(key, JsonUtil.getSimpleGson().toJson(goods), 60 * 20);
            LogHelper.test(auctionId + "-获取商品详情耗时:" + (System.currentTimeMillis() - startTime));
            return goods;
        } else {// 直接取缓存
            return JsonUtil.getSimpleGson().fromJson(value, TaoBaoGoodsBrief.class);
        }
    }
        if (StringUtil.isNullOrEmpty(value)) {
            List<ImageInfo> list = null;
            try {
                list = TaoBaoUtil.getTBDetailImageWithSizev2(auctionId, configService.getTaoBaoProxyIP(system));
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (list == null || list.size() == 0) {
                list = TaoBaoUtil.getTBDetailImageWithSize(auctionId);
            }
            if (list != null && list.size() > 0)
                // 缓存1天
                if (Constant.IS_OUTNET)
                cacheCommonString(key, JsonUtil.getSimpleGson().toJson(list), 60 * 60 * 24);
            return list;
        } else {// 直接取缓存
            List<ImageInfo> imgList = new Gson().fromJson(value, new TypeToken<List<ImageInfo>>() {
            }.getType());
            return imgList;
        }
    }
    public List<ImageInfo> getTaoBaoGoodsDetailImgs(long auctionId, SystemEnum system) {
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoGoodsDetailimgs, auctionId + "");
        String value = "";
        if (Constant.IS_OUTNET)
            value = getCommonString(key);
    public String getXCXCouponToken(TaoBaoGoodsBrief tb) {
        List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID);
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoCoupleXCX, tb.getAuctionId() + "");
        String value = "";
        if (Constant.IS_OUTNET)
            value = getCommonString(key);
        if (StringUtil.isNullOrEmpty(value)) {
            value = TaoKeApiUtil.getTKToken(tb.getPictUrl(), tb.getTitle(), TaoBaoCouponUtil
                    .getCoupleUrl(tb.getCouponActivityId(), configList.get(0).getDefaultPid(), tb.getAuctionId() + ""));
            if (value != null)
                // 缓存20分钟
                if (Constant.IS_OUTNET)
                cacheCommonString(key, value, 60 * 20);
            return value;
        } else {// 直接取缓存
            return value;
        }
    }
        if (StringUtil.isNullOrEmpty(value)) {
            List<ImageInfo> list = null;
            try {
                list = TaoBaoUtil.getTBDetailImageWithSizev2(auctionId, configService.getTaoBaoProxyIP(system));
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (list == null || list.size() == 0) {
                list = TaoBaoUtil.getTBDetailImageWithSize(auctionId);
            }
            if (list != null && list.size() > 0)
                // 缓存1天
                if (Constant.IS_OUTNET)
                    cacheCommonString(key, JsonUtil.getSimpleGson().toJson(list), 60 * 60 * 24);
            return list;
        } else {// 直接取缓存
            List<ImageInfo> imgList = new Gson().fromJson(value, new TypeToken<List<ImageInfo>>() {
            }.getType());
            return imgList;
        }
    }
    /**
     * IP访问频率限制 适用于 小程序,H5,WEB 同一IP,5s内限制请求100次
     *
     * @param ip
     */
    public boolean ipFrequencyLimit(String ip, String apiName) {
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.emptyKey, ip + "-" + StringUtil.Md5(apiName));
        Jedis jedis = jedisPool.getResource();
        try {
            long count = jedis.incr(key);
            if (count == 1)
                jedis.expire(key, 5);
            if (count >= 10)
                return true;
            else
                return false;
        } finally {
            jedis.close();
        }
    }
    public String getXCXCouponToken(TaoBaoGoodsBrief tb) {
        List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID);
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoCoupleXCX, tb.getAuctionId() + "");
        String value = "";
        if (Constant.IS_OUTNET)
            value = getCommonString(key);
        if (StringUtil.isNullOrEmpty(value)) {
            value = TaoKeApiUtil.getTKToken(tb.getPictUrl(), tb.getTitle(), TaoBaoCouponUtil
                    .getCoupleUrl(tb.getCouponActivityId(), configList.get(0).getDefaultPid(), tb.getAuctionId() + ""));
            if (value != null)
                // 缓存20分钟
                if (Constant.IS_OUTNET)
                    cacheCommonString(key, value, 60 * 20);
            return value;
        } else {// 直接取缓存
            return value;
        }
    }
    public boolean frequencyLimit(String key, int timeS, int num) {
        key = RedisKeyEnum.getRedisKey(RedisKeyEnum.frequencyLimit, key);
        Jedis jedis = jedisPool.getResource();
        try {
            long count = jedis.incr(key);
            if (count == 1)
                jedis.expire(key, timeS);
            if (count >= num)
                return true;
            else
                return false;
        } finally {
            jedis.close();
        }
    }
    /**
     * IP访问频率限制 适用于 小程序,H5,WEB 同一IP,5s内限制请求100次
     *
     * @param ip
     */
    public boolean ipFrequencyLimit(String ip, String apiName) {
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.emptyKey, ip + "-" + StringUtil.Md5(apiName));
        Jedis jedis = getJedis();
        try {
            long count = jedis.incr(key);
            if (count == 1)
                jedis.expire(key, 5);
            if (count >= 10)
                return true;
            else
                return false;
        } finally {
            jedis.close();
        }
    }
    /**
     * 获取淘宝图片
     *
     * @param auctionId
     * @return
     */
    public List<String> getTBImg(Long auctionId) {
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoImgs, auctionId + "");
        String value = "";
        if (Constant.IS_OUTNET)
            value = getCommonString(key);
        if (StringUtil.isNullOrEmpty(value)) {
            List<String> list = TaoBaoUtil.getTbImg(auctionId + "");
            if (Constant.IS_OUTNET && list != null && list.size() > 0) {
                value = new Gson().toJson(list);
                cacheCommonString(key, value, 60 * 60 * 2);
            }
            return list;
        } else {
            JSONArray array = JSONArray.fromObject(value);
            List<String> list = new ArrayList<>();
            for (int i = 0; i < array.size(); i++) {
                list.add(array.getString(i));
            }
            return list;
        }
    }
    public boolean frequencyLimit(String key, int timeS, int num) {
        key = RedisKeyEnum.getRedisKey(RedisKeyEnum.frequencyLimit, key);
        Jedis jedis = getJedis();
        try {
            long count = jedis.incr(key);
            if (count == 1)
                jedis.expire(key, timeS);
            if (count >= num)
                return true;
            else
                return false;
        } finally {
            jedis.close();
        }
    }
    /**
     * 获取淘宝店铺信息
     *
     * @param shopTitle
     * @param sellerId
     * @return
     */
    public TaoBaoShopInfo getTBShopInfo(String shopTitle, Long sellerId, Long auctionId) {
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoShop, sellerId +"");
        String value = "";
        if (Constant.IS_OUTNET)
            value = getCommonString(key);
    /**
     * 获取淘宝图片
     *
     * @param auctionId
     * @return
     */
    public List<String> getTBImg(Long auctionId) {
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoImgs, auctionId + "");
        String value = "";
        if (Constant.IS_OUTNET)
            value = getCommonString(key);
        if (StringUtil.isNullOrEmpty(value)) {
            List<String> list = TaoBaoUtil.getTbImg(auctionId + "");
            if (Constant.IS_OUTNET && list != null && list.size() > 0) {
                value = new Gson().toJson(list);
                cacheCommonString(key, value, 60 * 60 * 2);
            }
            return list;
        } else {
            JSONArray array = JSONArray.fromObject(value);
            List<String> list = new ArrayList<>();
            for (int i = 0; i < array.size(); i++) {
                list.add(array.getString(i));
            }
            return list;
        }
    }
        if (StringUtil.isNullOrEmpty(value)) {
            TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief();
            goods.setShopTitle(shopTitle);
            goods.setSellerId(sellerId);
            goods.setAuctionId(auctionId);
            TaoBaoShopInfo info = taoBaoShopService.getTaoBaoShopInfo(goods);
    /**
     * 获取淘宝店铺信息
     *
     * @param shopTitle
     * @param sellerId
     * @return
     */
    public TaoBaoShopInfo getTBShopInfo(String shopTitle, Long sellerId, Long auctionId) {
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoShop, sellerId + "");
        String value = "";
        if (Constant.IS_OUTNET)
            value = getCommonString(key);
            if (info != null) {
                String shopUrl = info.getShopUrl();
                if (shopUrl != null && shopUrl.contains("tmall://page.tm/shop")) {
                    shopUrl = "http://store.taobao.com/shop/view_shop.htm?user_number_id=" + sellerId;
                    info.setShopUrl(shopUrl);
                }
            }
        if (StringUtil.isNullOrEmpty(value)) {
            TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief();
            goods.setShopTitle(shopTitle);
            goods.setSellerId(sellerId);
            goods.setAuctionId(auctionId);
            TaoBaoShopInfo info = taoBaoShopService.getTaoBaoShopInfo(goods);
            if (Constant.IS_OUTNET && info != null) {
                value = new Gson().toJson(info);
                cacheCommonString(key, value, 60 * 60 * 2);
            }
            if (info != null) {
                String shopUrl = info.getShopUrl();
                if (shopUrl != null && shopUrl.contains("tmall://page.tm/shop")) {
                    shopUrl = "http://store.taobao.com/shop/view_shop.htm?user_number_id=" + sellerId;
                    info.setShopUrl(shopUrl);
                }
            }
            if (Constant.IS_OUTNET && info != null) {
                value = new Gson().toJson(info);
                cacheCommonString(key, value, 60 * 60 * 2);
            }
            return info;
        } else {
            TaoBaoShopInfo info = new Gson().fromJson(value, TaoBaoShopInfo.class);
            return info;
        } else {
            TaoBaoShopInfo info = new Gson().fromJson(value, TaoBaoShopInfo.class);
            String shopUrl = info.getShopUrl();
            if (shopUrl != null && shopUrl.contains("tmall://page.tm/shop")) {
                shopUrl = "http://store.taobao.com/shop/view_shop.htm?user_number_id=" + sellerId;
                info.setShopUrl(shopUrl);
            }
            String shopUrl = info.getShopUrl();
            if (shopUrl != null && shopUrl.contains("tmall://page.tm/shop")) {
                shopUrl = "http://store.taobao.com/shop/view_shop.htm?user_number_id=" + sellerId;
                info.setShopUrl(shopUrl);
            }
            return info;
        }
    }
            return info;
        }
    }
    /**
     * 是否限制发送短信
     *
     * @param phone
     * @param type
     * @return
     */
    public boolean isSmsFrequencyLimit(String phone, int type) {
        if (!Constant.IS_OUTNET)
            return false;
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMS,  phone + "-" + type);
        String value = getCommonString(key);
        if (StringUtil.isNullOrEmpty(value))
            return false;
        else
            return true;
    }
    /**
     * 是否限制发送短信
     *
     * @param phone
     * @param type
     * @return
     */
    public boolean isSmsFrequencyLimit(String phone, int type) {
        if (!Constant.IS_OUTNET)
            return false;
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMS, phone + "-" + type);
        String value = getCommonString(key);
        if (StringUtil.isNullOrEmpty(value))
            return false;
        else
            return true;
    }
    /**
     * 设置短信60s倒计时
     *
     * @param phone
     * @param type
     */
    public void sendSms(String phone, int type) {
        if (!Constant.IS_OUTNET)
            return;
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMS,  phone + "-" + type);
        setString(key, "1", 10);
    }
    /**
     * 设置短信60s倒计时
     *
     * @param phone
     * @param type
     */
    public void sendSms(String phone, int type) {
        if (!Constant.IS_OUTNET)
            return;
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMS, phone + "-" + type);
        setString(key, "1", 10);
    }
    public void clearSMSFrequencyLimit(String phone, int type) {
        if (!Constant.IS_OUTNET)
            return;
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMS,  phone + "-" + type);
        removeKey(key);
    }
    public void clearSMSFrequencyLimit(String phone, int type) {
        if (!Constant.IS_OUTNET)
            return;
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMS, phone + "-" + type);
        removeKey(key);
    }
    /**
     * 保存验证码
     *
     * @param phone
     * @param type
     * @param code
     */
    /**
     * 保存验证码
     *
     * @param phone
     * @param type
     * @param code
     */
    public void saveSMSVCode(String phone, int type, String code) {
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSVCode, phone + "-" + type);
        // 保存2分钟
        setString(key, code, 120);
    }
    public void saveSMSVCode(String phone, int type, String code) {
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSVCode, phone + "-" + type);
        // 保存2分钟
        setString(key, code, 120);
    }
    /**
     *
     * @param phone
     * @param type
     * @return
     */
    public String getSMSVCode(String phone, int type) {
        // if (!Constant.IS_OUTNET)
        // return "";
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSVCode, phone + "-" + type);
        // 保存2分钟
        return getString(key);
    }
    /**
     * @param phone
     * @param type
     * @return
     */
    public String getSMSVCode(String phone, int type) {
        // if (!Constant.IS_OUTNET)
        // return "";
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSVCode, phone + "-" + type);
        // 保存2分钟
        return getString(key);
    }
    /**
     * 清除掉验证码
     *
     * @param phone
     * @param type
     * @param code
     */
    public void clearSMSVCode(String phone, int type) {
        // if (!Constant.IS_OUTNET)
        // return;
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSVCode, phone + "-" + type);
        removeKey(key);
    }
    /**
     * 清除掉验证码
     *
     * @param phone
     * @param type
     * @param code
     */
    public void clearSMSVCode(String phone, int type) {
        // if (!Constant.IS_OUTNET)
        // return;
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSVCode, phone + "-" + type);
        removeKey(key);
    }
    /**
     * 保存绑定支付宝短信验证码的正确性
     */
    public void saveBindAlipayAccountSMSState(String phone) {
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSStateAlipay, phone + "" );
        // 验证后十分钟有效
        setString(key, "1", 10 * 60);
    }
    /**
     * 保存绑定支付宝短信验证码的正确性
     */
    public void saveBindAlipayAccountSMSState(String phone) {
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSStateAlipay, phone + "");
        // 验证后十分钟有效
        setString(key, "1", 10 * 60);
    }
    /**
     * 绑定支付宝发送的短信是否在有效期内
     *
     * @param phone
     * @return
     */
    public boolean isBindAlipayAccountSMSStateValid(String phone) {
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSStateAlipay, phone + "" );
        return !StringUtil.isNullOrEmpty(getString(key));
    }
    /**
     * 绑定支付宝发送的短信是否在有效期内
     *
     * @param phone
     * @return
     */
    public boolean isBindAlipayAccountSMSStateValid(String phone) {
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSStateAlipay, phone + "");
        return !StringUtil.isNullOrEmpty(getString(key));
    }
    /**
     * 缓存短连接1分钟
     *
     * @param uid
     * @param shortlink
     */
    public void setInviteShortLink(long uid, String shortlink) {
        String value = "";
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.inviteShortLink, uid + "" );
        if (Constant.IS_OUTNET) {
    /**
     * 缓存短连接1分钟
     *
     * @param uid
     * @param shortlink
     */
    public void setInviteShortLink(long uid, String shortlink) {
        String value = "";
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.inviteShortLink, uid + "");
        if (Constant.IS_OUTNET) {
            value = getCommonString(key);
            value = getCommonString(key);
            if (StringUtil.isNullOrEmpty(value)) {
                cacheCommonString(key, shortlink, 60);
            }
        }
            if (StringUtil.isNullOrEmpty(value)) {
                cacheCommonString(key, shortlink, 60);
            }
        }
    }
    }
    /**
     * 获取用户短连接
     *
     * @param uid
     * @return
     */
    public String getInviteShortLink(long uid) {
        String value = "";
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.inviteShortLink, uid + "" );
        if (Constant.IS_OUTNET)
            value = getCommonString(key);
    /**
     * 获取用户短连接
     *
     * @param uid
     * @return
     */
    public String getInviteShortLink(long uid) {
        String value = "";
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.inviteShortLink, uid + "");
        if (Constant.IS_OUTNET)
            value = getCommonString(key);
        return value;
    }
        return value;
    }
    /**
     * 保存淘口令
     *
     * @param auctionId
     * @param token
     */
    public void saveCommonTaoToken(Long auctionId, String token) {
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoTokenCommon, auctionId + "" );
        if (Constant.IS_OUTNET) {
            if (!StringUtil.isNullOrEmpty(token)) {
                // 口令缓存10天
                cacheCommonString(key, token, 60 * 60 * 24 * 10);
            }
        }
    }
    /**
     * 保存淘口令
     *
     * @param auctionId
     * @param token
     */
    public void saveCommonTaoToken(Long auctionId, String token) {
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoTokenCommon, auctionId + "");
        if (Constant.IS_OUTNET) {
            if (!StringUtil.isNullOrEmpty(token)) {
                // 口令缓存10天
                cacheCommonString(key, token, 60 * 60 * 24 * 10);
            }
        }
    }
    /**
     * 获取用户短连接
     *
     * @param uid
     * @return
     */
    public String getCommonTaoToken(Long auctionId) {
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoTokenCommon, auctionId + "" );
        if (Constant.IS_OUTNET) {
            return getCommonString(key);
        }
        return null;
    }
    /**
     * 获取用户短连接
     *
     * @param uid
     * @return
     */
    public String getCommonTaoToken(Long auctionId) {
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoTokenCommon, auctionId + "");
        if (Constant.IS_OUTNET) {
            return getCommonString(key);
        }
        return null;
    }
    /**
     * 保存淘礼金的口令
     *
     * @param url
     * @param token
     */
    public void saveTLJToken(String url, String token) {
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoTokenTLJ, StringUtil.Md5(url));
        if (Constant.IS_OUTNET) {
            if (!StringUtil.isNullOrEmpty(token)) {
                // 口令缓存10天
                cacheCommonString(key, token, 60 * 60 * 24 * 10);
            }
        }
    }
    /**
     * 保存淘礼金的口令
     *
     * @param url
     * @param token
     */
    public void saveTLJToken(String url, String token) {
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoTokenTLJ, StringUtil.Md5(url));
        if (Constant.IS_OUTNET) {
            if (!StringUtil.isNullOrEmpty(token)) {
                // 口令缓存10天
                cacheCommonString(key, token, 60 * 60 * 24 * 10);
            }
        }
    }
    /**
     * 获取淘礼金口令
     *
     * @param url
     * @return
     */
    public String getTLJToken(String url) {
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoTokenTLJ, StringUtil.Md5(url));
        if (Constant.IS_OUTNET) {
            return getCommonString(key);
        }
        return null;
    }
    /**
     * 获取淘礼金口令
     *
     * @param url
     * @return
     */
    public String getTLJToken(String url) {
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoTokenTLJ, StringUtil.Md5(url));
        if (Constant.IS_OUTNET) {
            return getCommonString(key);
        }
        return null;
    }
    /**
     * 保存对象
     *
     * @param T
     * @param key
     * @param seconds
     */
    public void saveObj(Object clazz, String key, Integer seconds) {
        if (clazz == null)
            return;
        String value = new Gson().toJson(clazz);
        if (seconds != null)
            cacheCommonString(key, value, seconds);
        else
            cacheCommonString(key, value);
    }
    /**
     * 保存对象
     *
     * @param T
     * @param key
     * @param seconds
     */
    public void saveObj(Object clazz, String key, Integer seconds) {
        if (clazz == null)
            return;
        String value = new Gson().toJson(clazz);
        if (seconds != null)
            cacheCommonString(key, value, seconds);
        else
            cacheCommonString(key, value);
    }
    /**
     * 保存列表
     *
     * @param clazzList
     * @param key
     * @param seconds
     */
    public <T> T saveObjList(List<T> clazzList, String key, Integer seconds) {
        if (clazzList == null)
            return null;
        String value = new Gson().toJson(clazzList);
        if (seconds != null)
            cacheCommonString(key, value, seconds);
        else
            cacheCommonString(key, value);
        return null;
    }
    /**
     * 保存列表
     *
     * @param clazzList
     * @param key
     * @param seconds
     */
    public <T> T saveObjList(List<T> clazzList, String key, Integer seconds) {
        if (clazzList == null)
            return null;
        String value = new Gson().toJson(clazzList);
        if (seconds != null)
            cacheCommonString(key, value, seconds);
        else
            cacheCommonString(key, value);
        return null;
    }
    /**
     * 获取对象
     *
     * @param clazz
     * @param key
     * @return
     */
    public Class<?> getObj(Class<?> clazz, String key) {
        String value = getCommonString(key);
        return (Class<?>) new Gson().fromJson(value, clazz);
    }
    /**
     * 获取对象
     *
     * @param clazz
     * @param key
     * @return
     */
    public Class<?> getObj(Class<?> clazz, String key) {
        String value = getCommonString(key);
        return (Class<?>) new Gson().fromJson(value, clazz);
    }
    /**
     * 获取列表
     *
     * @param clazz
     * @param key
     * @return
     */
    public <T> List<T> getObjList(Class<T> clazz, String key) {
        String value = getCommonString(key);
        return JsonUtil.jsonToList(value, clazz);
    }
    /**
     * 获取列表
     *
     * @param clazz
     * @param key
     * @return
     */
    public <T> List<T> getObjList(Class<T> clazz, String key) {
        String value = getCommonString(key);
        return JsonUtil.jsonToList(value, clazz);
    }
    public JDGoods getJDGoods(long goodsId) {
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.jingDongGoods, goodsId +"");
        String value = getCommonString(key);
        if (StringUtil.isNullOrEmpty(value)) {
            JDGoods jdGoods = JDApiUtil.queryGoodsDetail(goodsId);
            if (jdGoods == null) {
                jdGoods = JDApiUtil.getGoodsDetail(goodsId);
            }
    public JDGoods getJDGoods(long goodsId) {
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.jingDongGoods, goodsId + "");
        String value = getCommonString(key);
        if (StringUtil.isNullOrEmpty(value)) {
            JDGoods jdGoods = JDApiUtil.queryGoodsDetail(goodsId);
            if (jdGoods == null) {
                jdGoods = JDApiUtil.getGoodsDetail(goodsId);
            }
            // 缓存20分钟
            if (jdGoods != null)
                cacheCommonString(key, JsonUtil.getSimpleGson().toJson(jdGoods), 60 * 20);
            // 缓存20分钟
            if (jdGoods != null)
                cacheCommonString(key, JsonUtil.getSimpleGson().toJson(jdGoods), 60 * 20);
            return jdGoods;
        } else {// 直接取缓存
            return JsonUtil.getSimpleGson().fromJson(value, JDGoods.class);
        }
    }
            return jdGoods;
        } else {// 直接取缓存
            return JsonUtil.getSimpleGson().fromJson(value, JDGoods.class);
        }
    }
    public PDDGoodsDetail getPDDGoodsDetail(long goodsId) {
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.pinDuoDuoGoods, goodsId +"");
    public PDDGoodsDetail getPDDGoodsDetail(long goodsId) {
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.pinDuoDuoGoods, goodsId + "");
        String value = getCommonString(key);
        if (StringUtil.isNullOrEmpty(value)) {
            PDDGoodsDetail pddGoods = PinDuoDuoApiUtil.getGoodsDetail(goodsId);
        String value = getCommonString(key);
        if (StringUtil.isNullOrEmpty(value)) {
            PDDGoodsDetail pddGoods = PinDuoDuoApiUtil.getGoodsDetail(goodsId);
            // 缓存20分钟
            if (pddGoods != null)
                cacheCommonString(key, JsonUtil.getSimpleGson().toJson(pddGoods), 60 * 20);
            // 缓存20分钟
            if (pddGoods != null)
                cacheCommonString(key, JsonUtil.getSimpleGson().toJson(pddGoods), 60 * 20);
            return pddGoods;
        } else {// 直接取缓存
            return JsonUtil.getSimpleGson().fromJson(value, PDDGoodsDetail.class);
        }
    }
            return pddGoods;
        } else {// 直接取缓存
            return JsonUtil.getSimpleGson().fromJson(value, PDDGoodsDetail.class);
        }
    }
}
fanli/src/main/resource/env-dev/redis.properties
@@ -1,11 +1,12 @@
redis.addr=192.168.1.253
redis.port=6379
redis.port=6379
redis.auth=123456
#redis.addr=193.112.34.40
#redis.port=6379
#redis.auth=weikou2014
redis.max_total=1024
redis.max_total=1024
redis.max_idle=200
redis.max_wait=10000
redis.timeout=5000
redis.database=0
redis.test_on_borrow=true
fanli/src/main/resource/env-pro-by/redis.properties
@@ -5,4 +5,5 @@
redis.max_idle=200
redis.max_wait=10000
redis.timeout=5000
redis.test_on_borrow=true
redis.test_on_borrow=true
redis.database=0
fanli/src/main/resource/env-pro-job/redis.properties
@@ -5,4 +5,5 @@
redis.max_idle=200
redis.max_wait=10000
redis.timeout=5000
redis.test_on_borrow=true
redis.test_on_borrow=true
redis.database=1
fanli/src/main/resource/env-pro/redis.properties
@@ -5,4 +5,5 @@
redis.max_idle=200
redis.max_wait=10000
redis.timeout=5000
redis.test_on_borrow=true
redis.test_on_borrow=true
redis.database=0
fanli/src/main/resource/env-sandbox/redis.properties
@@ -1,9 +1,10 @@
redis.addr=172.16.16.3
redis.port=6379
redis.port=6379
redis.auth=weikou2014
#控制一个pool可分配多少个jedis实例,
redis.max_total=-1
redis.max_total=-1
redis.max_idle=200
redis.max_wait=10000
redis.timeout=5000
redis.test_on_borrow=true
redis.database=0
fanli/src/main/resource/spring.xml
@@ -247,6 +247,8 @@
        <constructor-arg name="port" value="${redis.port}"></constructor-arg>
        <constructor-arg name="timeout" value="${redis.timeout}"></constructor-arg>
        <constructor-arg name="password" value="${redis.auth}"></constructor-arg>
        <constructor-arg name="database" value="${redis.database}"></constructor-arg>
    </bean>