Parcourir la source

feat:写入二进制的特征

zhaohaipeng il y a 1 semaine
Parent
commit
34c5101b22

+ 7 - 1
recommend-feature-produce/src/main/java/com/tzld/piaoquan/recommend/feature/produce/service/RedisService.java

@@ -5,12 +5,12 @@ import com.tzld.piaoquan.recommend.feature.produce.util.CompressionUtil;
 import com.tzld.piaoquan.recommend.feature.produce.util.JSONUtils;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.MapUtils;
-import org.apache.commons.lang3.RandomUtils;
 import org.apache.commons.lang3.StringUtils;
 import redis.clients.jedis.Jedis;
 import redis.clients.jedis.Pipeline;
 
 import java.io.Serializable;
+import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -91,6 +91,12 @@ public class RedisService implements Serializable {
                 pipeline.setex(e.getKey(), expireSeconds, CompressionUtil.snappyCompress(e.getValue()));
             } catch (Exception ex) {
             }
+
+            try {
+                String newKey = String.format("%s:v2", e.getKey());
+                pipeline.setex(newKey.getBytes(StandardCharsets.UTF_8), expireSeconds, CompressionUtil.snappyCompressV2(e.getValue()));
+            } catch (Exception ignore) {
+            }
         }
         pipeline.sync();
 

+ 5 - 0
recommend-feature-produce/src/main/java/com/tzld/piaoquan/recommend/feature/produce/util/CompressionUtil.java

@@ -66,6 +66,11 @@ public class CompressionUtil {
         return Base64.getEncoder().encodeToString(compressedBytes);
     }
 
+    public static byte[] snappyCompressV2(String input) throws IOException{
+        byte[] inputBytes = input.getBytes(StandardCharsets.UTF_8);
+        return Snappy.compress(inputBytes);
+    }
+
     // 将Snappy压缩后的String解压缩回String
     public static String snappyDecompress(String compressedInput) throws IOException {
         byte[] compressedBytes = Base64.getDecoder().decode(compressedInput);