|
|
@@ -1,11 +1,10 @@
|
|
|
package com.tzld.piaoquan.recommend.feature.produce.service;
|
|
|
|
|
|
import com.tzld.piaoquan.recommend.feature.common.model.DTSConfig;
|
|
|
-import com.tzld.piaoquan.recommend.feature.common.util.RedisUtil;
|
|
|
import com.tzld.piaoquan.recommend.feature.common.util.CompressionUtil;
|
|
|
import com.tzld.piaoquan.recommend.feature.common.util.JSONUtils;
|
|
|
+import com.tzld.piaoquan.recommend.feature.common.util.RedisUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.collections.MapUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import redis.clients.jedis.Jedis;
|
|
|
@@ -13,7 +12,9 @@ import redis.clients.jedis.Pipeline;
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
-import java.util.*;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Iterator;
|
|
|
+import java.util.Map;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
|
@@ -31,6 +32,9 @@ public class RedisService implements Serializable {
|
|
|
if (StringUtils.equals(env, "prod")) {
|
|
|
password = "Wqsd@2019";
|
|
|
hostName = "r-bp1pi8wyv6lzvgjy5z.redis.rds.aliyuncs.com";
|
|
|
+ } else if (StringUtils.equals(env, "prod_disk")) {
|
|
|
+ password = "Wqsd@2019";
|
|
|
+ hostName = "r-bp1r5em55k87e2xb1k.tairpdb.rds.aliyuncs.com";
|
|
|
} else {
|
|
|
password = "Wqsd@2019";
|
|
|
hostName = "r-bp1wwqqkjqwwkxgbup.redis.rds.aliyuncs.com";
|
|
|
@@ -77,26 +81,6 @@ public class RedisService implements Serializable {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void delete(Iterator<Map<String, String>> dataIte, DTSConfig config) {
|
|
|
- log.info("delete param: {}", config);
|
|
|
- List<String> batch = new ArrayList<>();
|
|
|
- Jedis jedis = new Jedis(hostName, port);
|
|
|
- jedis.auth(password);
|
|
|
- while (dataIte.hasNext()) {
|
|
|
- Map<String, String> record = dataIte.next();
|
|
|
- String redisKey = RedisUtil.buildRedisKey(record, config);
|
|
|
- batch.add(redisKey);
|
|
|
- if (batch.size() >= 1000) {
|
|
|
- delete(jedis, batch);
|
|
|
- batch.clear();
|
|
|
- }
|
|
|
- }
|
|
|
- if (CollectionUtils.isNotEmpty(batch)) {
|
|
|
- delete(jedis, batch);
|
|
|
- }
|
|
|
- jedis.close();
|
|
|
- }
|
|
|
-
|
|
|
private void mSet(Jedis jedis, Map<String, String> batch, long expire, TimeUnit timeUnit) {
|
|
|
long expireSeconds = timeUnit.toSeconds(expire);
|
|
|
|
|
|
@@ -112,16 +96,4 @@ public class RedisService implements Serializable {
|
|
|
|
|
|
}
|
|
|
|
|
|
- private void delete(Jedis jedis, List<String> keys) {
|
|
|
- Pipeline pipeline = jedis.pipelined();
|
|
|
- for (String key : keys) {
|
|
|
- try {
|
|
|
- pipeline.del(String.format("%s:v2", key).getBytes(StandardCharsets.UTF_8));
|
|
|
- } catch (Exception ignore) {
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- pipeline.sync();
|
|
|
- }
|
|
|
-
|
|
|
}
|