admin
2019-07-19 cbe9871d77e3586015f26d7e7c78d254bb8ec6f6
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;
@@ -111,7 +111,7 @@
      }
   }
   public void expire(String key,int seconds) {
   public void expire(String key, int seconds) {
      Jedis jedis = jedisPool.getResource();
      try {
         jedis.expire(key, seconds);
@@ -253,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;
@@ -384,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);
@@ -398,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);
@@ -413,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);
   }
@@ -509,4 +507,94 @@
      return null;
   }
   /**
    * 保存淘礼金的口令
    *
    * @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)) {
            // 口令缓存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);
   }
}