From 573c491b4a1ba60e12a5678a01c1546c0077c1ee Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 30 七月 2019 09:07:42 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- fanli/src/main/java/com/yeshi/fanli/util/RedisManager.java | 144 +++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 123 insertions(+), 21 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/util/RedisManager.java b/fanli/src/main/java/com/yeshi/fanli/util/RedisManager.java index 8899c7a..fa63cfe 100644 --- a/fanli/src/main/java/com/yeshi/fanli/util/RedisManager.java +++ b/fanli/src/main/java/com/yeshi/fanli/util/RedisManager.java @@ -6,6 +6,7 @@ import javax.annotation.Resource; import org.springframework.stereotype.Component; +import org.yeshi.utils.JsonUtil; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; @@ -22,7 +23,6 @@ import com.yeshi.fanli.util.taobao.TaoBaoCouponUtil; import com.yeshi.fanli.util.taobao.TaoBaoUtil; import com.yeshi.fanli.util.taobao.TaoKeApiUtil; -import org.yeshi.utils.JsonUtil; import net.sf.json.JSONArray; import redis.clients.jedis.Jedis; @@ -97,6 +97,24 @@ Jedis jedis = jedisPool.getResource(); try { return jedis.get(key); + } finally { + jedisPool.returnResource(jedis); + } + } + + public void increase(String key) { + Jedis jedis = jedisPool.getResource(); + try { + jedis.incr(key); + } finally { + jedisPool.returnResource(jedis); + } + } + + public void expire(String key, int seconds) { + Jedis jedis = jedisPool.getResource(); + try { + jedis.expire(key, seconds); } finally { jedisPool.returnResource(jedis); } @@ -235,7 +253,7 @@ long count = jedis.incr(key); if (count == 1) jedis.expire(key, 5); - if (count >= 100) + if (count >= 10) return true; else return false; @@ -284,37 +302,37 @@ String value = ""; if (Constant.IS_OUTNET) value = getCommonString(key); - + if (StringUtil.isNullOrEmpty(value)) { TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief(); goods.setShopTitle(shopTitle); goods.setSellerId(sellerId); goods.setAuctionId(auctionId); TaoBaoShopInfo info = taoBaoShopService.getTaoBaoShopInfo(goods); - - if(info != null) { + + if (info != null) { String shopUrl = info.getShopUrl(); - if(shopUrl != null && shopUrl.contains("tmall://page.tm/shop")) { + 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); - + String shopUrl = info.getShopUrl(); - if(shopUrl != null && shopUrl.contains("tmall://page.tm/shop")) { + 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; } } @@ -336,10 +354,6 @@ else return true; } - - - - /** * 璁剧疆鐭俊60s鍊掕鏃� @@ -370,8 +384,6 @@ */ public void saveSMSVCode(String phone, int type, String code) { - if (!Constant.IS_OUTNET) - return; String key = "smscode-" + phone + "-" + type; // 淇濆瓨2鍒嗛挓 setString(key, code, 120); @@ -384,8 +396,8 @@ * @return */ public String getSMSVCode(String phone, int type) { - if (!Constant.IS_OUTNET) - return ""; +// if (!Constant.IS_OUTNET) +// return ""; String key = "smscode-" + phone + "-" + type; // 淇濆瓨2鍒嗛挓 return getString(key); @@ -399,8 +411,8 @@ * @param code */ public void clearSMSVCode(String phone, int type) { - if (!Constant.IS_OUTNET) - return; +// if (!Constant.IS_OUTNET) +// return; String key = "smscode-" + phone + "-" + type; removeKey(key); } @@ -495,4 +507,94 @@ return null; } + /** + * 淇濆瓨娣樼ぜ閲戠殑鍙d护 + * + * @param url + * @param token + */ + public void saveTLJToken(String url, String token) { + String key = "taobao-tlj-token-" + StringUtil.Md5(url); + if (Constant.IS_OUTNET) { + if (!StringUtil.isNullOrEmpty(token)) { + // 鍙d护缂撳瓨10澶� + cacheCommonString(key, token, 60 * 60 * 24 * 10); + } + } + } + + /** + * 鑾峰彇娣樼ぜ閲戝彛浠� + * + * @param url + * @return + */ + public String getTLJToken(String url) { + String key = "taobao-common-token-" + StringUtil.Md5(url); + + if (Constant.IS_OUTNET) { + return getCommonString(key); + } + return null; + } + + /** + * 淇濆瓨瀵硅薄 + * + * @param T + * @param key + * @param seconds + */ + public void saveObj(Class<?> 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 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); + } + } -- Gitblit v1.8.0