Beispiel #1
0
 public static void initMap() {
   NSimpleHibernateDao nSimpleHibernateDao = SpringContextHolder.getBean("NSimpleHibernateDao");
   String hql = "from BaseDataList where typeuuid='emot'";
   List<BaseDataList> list =
       (List<BaseDataList>) nSimpleHibernateDao.getHibernateTemplate().find(hql);
   map.clear();
   for (BaseDataList o : list) {
     String url =
         ProjectProperties.getProperty(
             "share_url_getEmot", "http://kd.wenjienet.com/px-rest/i/emoji/");
     map.put(o.getDatavalue(), url + o.getDescription());
   }
 }
/** 基于redis 缓存家庭照片图片uuid */
public class FPPhotoRedisCache {
  // 用户信息,全部存到redies中

  private static Logger logger = Logger.getLogger("FPPhotoRedisCache");

  private static Jedis getJedis() {
    return PxRedisCacheImpl.getJedis();
  }

  private static NSimpleHibernateDao nSimpleHibernateDao =
      SpringContextHolder.getBean("NSimpleHibernateDao");

  /**
   * 获取上传地址,每次调用缓存延长24小时
   *
   * @param uuid
   * @return
   * @throws IOException
   */
  public static String getUploadFilePath(String uuid) {
    Jedis jedis = getJedis();
    Response<String> pathResponse;
    try {
      String key = CacheConstants.Redis_String_PhotoPath + uuid;

      // if(true)return jedis.get(key);
      Pipeline p = jedis.pipelined();
      pathResponse = p.get(key);
      p.expire(key, CacheConstants.Redis_String_PhotoPath_Expire);
      p.sync();
      p.close();
      //		    List<Object> results = p.syncAndReturnAll();
      String path = pathResponse.get();
      if (path != null) return path;
      List list =
          nSimpleHibernateDao
              .createSqlQuery("select path from fp_photo_item where uuid='" + uuid + "'")
              .list();

      if (list != null && list.size() > 0) {
        path = (String) list.get(0);
        setUploadFilePath(uuid, path);
      } else { // 防止暴力查数据库
        setUploadFilePath(uuid, "");
      }
      return path;
    } catch (Exception e) {
      //// e.printStackTrace();
      throw e;
    } finally {
      if (jedis != null) jedis.close();
    }
  }
  /**
   * 设置上传地址到缓存中.缓存延长24小时
   *
   * @param uuid
   * @param path
   */
  public static void setUploadFilePath(String uuid, String path) {
    Jedis jedis = getJedis();
    try {
      String key = CacheConstants.Redis_String_PhotoPath + uuid;
      jedis.setex(key, CacheConstants.Redis_String_PhotoPath_Expire, path);
    } catch (Exception e) {
      // e.printStackTrace();
      throw e;
    } finally {
      if (jedis != null) jedis.close();
    }
  }
}