yumeng 1 週間 前
コミット
ff33f8524a

+ 11 - 4
src/main/java/com/adx/tencent/honor/store/HonorHotStore.java

@@ -32,6 +32,7 @@ import java.util.concurrent.ConcurrentHashMap;
 public class HonorHotStore {
 
     private static final Logger log = LoggerFactory.getLogger(HonorHotStore.class);
+    private static final Duration IMPRESSION_BID_TTL = Duration.ofHours(3);
 
     private final StringRedisTemplate redis;
     private final ObjectMapper objectMapper;
@@ -62,7 +63,7 @@ public class HonorHotStore {
             redis.executePipelined((org.springframework.data.redis.connection.RedisConnection conn) -> {
                 trimStreamIfNeeded(conn);
                 byte[] hotBytes = hotPayload.getBytes(StandardCharsets.UTF_8);
-                long ttlMillis = bidTtl.toMillis();
+                long ttlMillis = bidTtlFor(record.getEventType()).toMillis();
                 conn.stringCommands().set(
                         bidKey(record.getQk()).getBytes(StandardCharsets.UTF_8),
                         hotBytes,
@@ -102,9 +103,7 @@ public class HonorHotStore {
         try {
             String slimPayload = objectMapper.writeValueAsString(record.toPostClickRecord());
             byte[] slimBytes = slimPayload.getBytes(StandardCharsets.UTF_8);
-            Long remainingTtl = redis.getExpire(bidKey(record.getQk()), java.util.concurrent.TimeUnit.MILLISECONDS);
-            if (remainingTtl == null || remainingTtl <= 0) remainingTtl = bidTtl.toMillis();
-            long ttlMs = remainingTtl;
+            long ttlMs = resolvedBidTtl().toMillis();
             redis.executePipelined((org.springframework.data.redis.connection.RedisConnection conn) -> {
                 conn.stringCommands().set(
                         bidKey(record.getQk()).getBytes(StandardCharsets.UTF_8),
@@ -131,6 +130,14 @@ public class HonorHotStore {
         return parseBidRecord(payload);
     }
 
+    private Duration bidTtlFor(String eventType) {
+        return "impression".equalsIgnoreCase(eventType) ? IMPRESSION_BID_TTL : resolvedBidTtl();
+    }
+
+    private Duration resolvedBidTtl() {
+        return (bidTtl == null || bidTtl.isZero()) ? Duration.ofHours(36) : bidTtl;
+    }
+
     public Map<String, HonorBidRecord> findBidsByQks(List<String> qks) {
         if (qks == null || qks.isEmpty()) return Collections.emptyMap();
         Map<String, HonorBidRecord> result = new HashMap<>();

+ 11 - 4
src/main/java/com/adx/tencent/kuaishou/store/KuaishouHotStore.java

@@ -35,6 +35,7 @@ import java.util.concurrent.ConcurrentHashMap;
 public class KuaishouHotStore {
 
     private static final Logger log = LoggerFactory.getLogger(KuaishouHotStore.class);
+    private static final Duration IMPRESSION_BID_TTL = Duration.ofHours(3);
     private static final Duration DEFAULT_CONVERSION_SEEN_TTL = Duration.ofDays(7);
     private static final Duration DEFAULT_DEDUCTION_COUNTER_TTL = Duration.ofDays(7);
 
@@ -69,7 +70,7 @@ public class KuaishouHotStore {
             redis.executePipelined((org.springframework.data.redis.connection.RedisConnection conn) -> {
                 trimStreamIfNeeded(conn);
                 byte[] hotBytes = hotPayload.getBytes(StandardCharsets.UTF_8);
-                long ttlMillis = bidTtl.toMillis();
+                long ttlMillis = bidTtlFor(record.getEventType()).toMillis();
                 if (record.getQk() != null && !record.getQk().isBlank()) {
                     conn.stringCommands().set(
                             bidKey(record.getQk()).getBytes(StandardCharsets.UTF_8),
@@ -112,9 +113,7 @@ public class KuaishouHotStore {
         try {
             String slimPayload = objectMapper.writeValueAsString(record.toPostClickRecord());
             byte[] slimBytes = slimPayload.getBytes(StandardCharsets.UTF_8);
-            Long remainingTtl = redis.getExpire(bidKey(record.getQk()), java.util.concurrent.TimeUnit.MILLISECONDS);
-            if (remainingTtl == null || remainingTtl <= 0) remainingTtl = bidTtl.toMillis();
-            long ttlMs = remainingTtl;
+            long ttlMs = resolvedBidTtl().toMillis();
             redis.executePipelined((org.springframework.data.redis.connection.RedisConnection conn) -> {
                 if (record.getQk() != null && !record.getQk().isBlank()) {
                     conn.stringCommands().set(
@@ -145,6 +144,14 @@ public class KuaishouHotStore {
         return parseBidRecord(payload);
     }
 
+    private Duration bidTtlFor(String eventType) {
+        return "impression".equalsIgnoreCase(eventType) ? IMPRESSION_BID_TTL : resolvedBidTtl();
+    }
+
+    private Duration resolvedBidTtl() {
+        return (bidTtl == null || bidTtl.isZero()) ? Duration.ofHours(36) : bidTtl;
+    }
+
     public Map<String, KuaishouBidRecord> findBidsByQks(List<String> qks) {
         if (qks == null || qks.isEmpty()) return Collections.emptyMap();
         Map<String, KuaishouBidRecord> result = new HashMap<>();

+ 7 - 5
src/main/java/com/adx/tencent/storage/RedisHotStore.java

@@ -24,6 +24,7 @@ import java.util.concurrent.ConcurrentHashMap;
 public class RedisHotStore {
 
     public static final String BID_NOT_FOUND_MSG = "bid not found";
+    private static final Duration IMPRESSION_BID_TTL = Duration.ofHours(3);
     private static final Duration DEFAULT_CONVERSION_SEEN_TTL = Duration.ofDays(7);
     private static final Duration DEFAULT_DEDUCTION_COUNTER_TTL = Duration.ofDays(7);
 
@@ -72,7 +73,7 @@ public class RedisHotStore {
             redis.executePipelined((org.springframework.data.redis.connection.RedisConnection conn) -> {
                 trimStreamIfNeeded(conn);
                 byte[] hotBytes = hotPayload.getBytes(StandardCharsets.UTF_8);
-                long ttlMillis = bidTtl.toMillis();
+                long ttlMillis = bidTtlFor(record.getEventType()).toMillis();
                 if (record.getQk() != null && !record.getQk().isEmpty()) {
                     conn.stringCommands().set(
                             bidKey(record.getQk()).getBytes(StandardCharsets.UTF_8),
@@ -132,10 +133,7 @@ public class RedisHotStore {
         try {
             String slimPayload = objectMapper.writeValueAsString(record.toPostClickRecord());
             byte[] slimBytes = slimPayload.getBytes(StandardCharsets.UTF_8);
-            // 获取剩余 TTL,保持原有过期时间
-            Long remainingTtl = redis.getExpire(bidKey(record.getQk()), java.util.concurrent.TimeUnit.MILLISECONDS);
-            if (remainingTtl == null || remainingTtl <= 0) remainingTtl = bidTtl.toMillis();
-            long ttlMs = remainingTtl;
+            long ttlMs = bidTtl.toMillis();
 
             redis.executePipelined((org.springframework.data.redis.connection.RedisConnection conn) -> {
                 if (record.getQk() != null && !record.getQk().isEmpty()) {
@@ -174,6 +172,10 @@ public class RedisHotStore {
         return null;
     }
 
+    private Duration bidTtlFor(String eventType) {
+        return "impression".equalsIgnoreCase(eventType) ? IMPRESSION_BID_TTL : bidTtl;
+    }
+
     public Map<String, BidRecord> findBidsByQks(List<String> qks) {
         if (qks == null || qks.isEmpty()) return Collections.emptyMap();
         Map<String, BidRecord> result = new HashMap<>();

+ 11 - 4
src/main/java/com/adx/tencent/vivo/store/VivoHotStore.java

@@ -35,6 +35,7 @@ import java.util.concurrent.ConcurrentHashMap;
 public class VivoHotStore {
 
     private static final Logger log = LoggerFactory.getLogger(VivoHotStore.class);
+    private static final Duration IMPRESSION_BID_TTL = Duration.ofHours(3);
     private static final Duration DEFAULT_CONVERSION_SEEN_TTL = Duration.ofDays(7);
     private static final Duration DEFAULT_DEDUCTION_COUNTER_TTL = Duration.ofDays(7);
 
@@ -69,7 +70,7 @@ public class VivoHotStore {
             redis.executePipelined((org.springframework.data.redis.connection.RedisConnection conn) -> {
                 trimStreamIfNeeded(conn);
                 byte[] hotBytes = hotPayload.getBytes(StandardCharsets.UTF_8);
-                long ttlMillis = bidTtl.toMillis();
+                long ttlMillis = bidTtlFor(record.getEventType()).toMillis();
                 if (record.getQk() != null && !record.getQk().isBlank()) {
                     conn.stringCommands().set(
                             bidKey(record.getQk()).getBytes(StandardCharsets.UTF_8),
@@ -112,9 +113,7 @@ public class VivoHotStore {
         try {
             String slimPayload = objectMapper.writeValueAsString(record.toPostClickRecord());
             byte[] slimBytes = slimPayload.getBytes(StandardCharsets.UTF_8);
-            Long remainingTtl = redis.getExpire(bidKey(record.getQk()), java.util.concurrent.TimeUnit.MILLISECONDS);
-            if (remainingTtl == null || remainingTtl <= 0) remainingTtl = bidTtl.toMillis();
-            long ttlMs = remainingTtl;
+            long ttlMs = resolvedBidTtl().toMillis();
             redis.executePipelined((org.springframework.data.redis.connection.RedisConnection conn) -> {
                 if (record.getQk() != null && !record.getQk().isBlank()) {
                     conn.stringCommands().set(
@@ -145,6 +144,14 @@ public class VivoHotStore {
         return parseBidRecord(payload);
     }
 
+    private Duration bidTtlFor(String eventType) {
+        return "impression".equalsIgnoreCase(eventType) ? IMPRESSION_BID_TTL : resolvedBidTtl();
+    }
+
+    private Duration resolvedBidTtl() {
+        return (bidTtl == null || bidTtl.isZero()) ? Duration.ofHours(36) : bidTtl;
+    }
+
     public Map<String, VivoBidRecord> findBidsByQks(List<String> qks) {
         if (qks == null || qks.isEmpty()) return Collections.emptyMap();
         Map<String, VivoBidRecord> result = new HashMap<>();