Пример #1
0
  /**
   * 获取上传地址,每次调用缓存延长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();
    }
  }
Пример #2
0
 public void pipelineWithoutTransaction() {
   Jedis jedis = pool.getResource();
   try {
     Pipeline p = jedis.pipelined();
     for (int i = 0; i < rowCount; i++) {
       String key = RandomStringUtils.randomAlphabetic(8);
       p.set(key, RandomStringUtils.randomNumeric(5));
       p.expire(key, 5 * 60);
     }
     p.sync();
   } catch (Exception e) {
     pool.returnResource(jedis);
   }
 }
Пример #3
0
  @Override
  protected void updateStatesToRedis(RedisState redisState, Map<String, String> keyToValue) {
    Jedis jedis = null;
    try {
      jedis = redisState.getJedis();
      Pipeline pipeline = jedis.pipelined();

      for (Map.Entry<String, String> kvEntry : keyToValue.entrySet()) {
        String key = kvEntry.getKey();
        String value = kvEntry.getValue();

        switch (dataType) {
          case STRING:
            if (this.expireIntervalSec > 0) {
              pipeline.setex(key, expireIntervalSec, value);
            } else {
              pipeline.set(key, value);
            }
            break;
          case HASH:
            pipeline.hset(additionalKey, key, value);
            break;
          default:
            throw new IllegalArgumentException("Cannot process such data type: " + dataType);
        }
      }

      // send expire command for hash only once
      // it expires key itself entirely, so use it with caution
      if (dataType == RedisDataTypeDescription.RedisDataType.HASH && this.expireIntervalSec > 0) {
        pipeline.expire(additionalKey, expireIntervalSec);
      }

      pipeline.sync();
    } finally {
      if (jedis != null) {
        redisState.returnJedis(jedis);
      }
    }
  }