コード例 #1
1
 private void initSet(RedisSchnauzer table, ResultSet rs) {
   try {
     rs.first();
     String preKey = table.table.SlaveKey;
     String key = "";
     String member = "";
     Double score = 0.0;
     String value = "";
     int rowCount = 0;
     Boolean haveKey = table.table.haveKeyFields();
     rs.beforeFirst();
     RedisStructure type = table.getType();
     while (rs.next()) {
       switch (type) {
         case Set:
         case SortedSet:
           if (haveKey) {
             key = rs.getString(1);
             member = rs.getString(2);
             score = rs.getDouble(3);
           } else {
             key = "";
             member = rs.getString(1);
             score = rs.getDouble(2);
           }
           dbhelper.zincrby(preKey + key, score, member);
           break;
         case String:
           key = rs.getString(1);
           value = rs.getString(2);
           dbhelper.set(preKey + key, value);
           break;
         default:
           ErrorHelper.errExit(LOGGER.getName() + " '" + table.getType() + "' Not Impliment....");
       }
       rowCount = rowCount + 1;
     }
     LOGGER.info("load " + preKey + " OK. rowcount=" + rowCount);
     rs.close();
   } catch (Exception e) {
     ErrorHelper.errExit(
         LOGGER.getName()
             + Infos.Init
             + "RedisData"
             + Infos.Failed
             + ": "
             + table.table.SlaveKey
             + ": "
             + e.getMessage());
   }
 }
コード例 #2
0
  private void innerDelete(ColumnTypeHelper helper, DeleteRowsEvent event, RedisSchnauzer table)
      throws UnsupportedEncodingException {
    List<Row> rows = event.getRows();
    LOGGER.info(rows.size() + Infos.Row);
    int scoreIndex = table.getMemberIndex();
    int memberIndex = table.getScoreIndex();
    int valueIndex = table.getValueIndex();
    Double score = 0.0;
    String member = "";
    String value = "";
    for (int j = 0; j < rows.size(); j++) {
      Row row = rows.get(j);
      List<Column> columns = row.getColumns();
      if (!table.needReplicate(columns, helper)) continue;
      switch (table.getType()) {
        case String:
          dbhelper.delete(table.getKey(columns));
          dbhelper.setBinlogKey(
              getBinLogName(helper), Long.toString(helper.position), helper.tableName);
          break;

        case Set:
          score = -1.00;
          value =
              helper.getColStr(
                  valueIndex,
                  columns.get(valueIndex),
                  (byte) 1,
                  table.masterfields.get(valueIndex));
          dbhelper.zincrby(table.getKey(columns), score, value);
          dbhelper.setBinlogKey(
              getBinLogName(helper), Long.toString(helper.position), helper.tableName);
          break;
        case SortedSet:
          score =
              Double.parseDouble(
                      helper.getColStr(
                          scoreIndex,
                          columns.get(scoreIndex),
                          (byte) 1,
                          table.masterfields.get(scoreIndex)))
                  * table.scorefield.multiplier;
          member =
              helper.getColStr(
                  memberIndex,
                  columns.get(memberIndex),
                  (byte) 1,
                  table.masterfields.get(memberIndex));
          dbhelper.zincrby(table.getKey(columns), -1 * score, member);
          dbhelper.setBinlogKey(
              getBinLogName(helper), Long.toString(helper.position), helper.tableName);
          break;
        case List:
          ErrorHelper.errExit(
              "innerDelete====" + Infos.Illegal + "RedisStructure:" + table.getType().toString());
          break;
        default:
          ErrorHelper.errExit(
              "innerDelete====" + Infos.Illegal + "RedisStructure:" + table.getType().toString());
          break;
      }
    }
  }